#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int help();
int hexarg2binfile(char *, int /*<<< orphan*/ *);
int hexfile2binfile(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int err = 0;
  if (argc == 1) {
    return hexfile2binfile(stdin, stdout);
  }
  if (argc == 2) {
    if (strncmp(argv[1], "-h", strlen("-h")) == 0 ||
        strncmp(argv[1], "--help", strlen("--help")) == 0) {
      return help();
    } else {
      return hexarg2binfile(argv[1], stdout);
    }
  }
  if (argc == 3) {
    FILE *outfile = fopen(argv[2], "w");
    if (strncmp(argv[1], "-stdin", strlen("-stdin")) == 0) {
      err = hexfile2binfile(stdin, outfile);
    } else {
      err = hexarg2binfile(argv[1], outfile);
    }
    fclose(outfile);
    return err;
  }
  if (argc > 3) {
    return help();
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11b7 <main+0x47>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%rsi
call   1060 <hexfile2binfile@plt>
mov    %eax,-0x4(%rbp)
jmp    1303 <main+0x193>
cmpl   $0x2,-0x8(%rbp)
jne    1257 <main+0xe7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
lea    0xe2c(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe1a(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1229 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
lea    0xdfb(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xde9(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1238 <main+0xc8>
mov    $0x0,%al
call   1090 <help@plt>
mov    %eax,-0x4(%rbp)
jmp    1303 <main+0x193>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d91(%rip),%rax
mov    (%rax),%rsi
call   1070 <hexarg2binfile@plt>
mov    %eax,-0x4(%rbp)
jmp    1303 <main+0x193>
cmpl   $0x3,-0x8(%rbp)
jne    12ef <main+0x17f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd9a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
lea    0xd80(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xd6e(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12c7 <main+0x157>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
call   1060 <hexfile2binfile@plt>
mov    %eax,-0x14(%rbp)
jmp    12db <main+0x16b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <hexarg2binfile@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1303 <main+0x193>
cmpl   $0x3,-0x8(%rbp)
jle    1303 <main+0x193>
mov    $0x0,%al
call   1090 <help@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
je     11b1 <main+0x41>
cmp    $0x2,%edi
je     11fe <main+0x8e>
cmp    $0x1,%edi
jne    1266 <main+0xf6>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <hexfile2binfile@plt>
mov    0x10(%rbx),%rdi
lea    0xe4e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    0x8(%rbx),%r15
lea    0xe3d(%rip),%r12
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     127f <main+0x10f>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   1070 <hexarg2binfile@plt>
jmp    1290 <main+0x120>
mov    0x8(%rbx),%r14
lea    0xdf7(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     126d <main+0xfd>
mov    0x8(%rbx),%r14
lea    0xdd5(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     126d <main+0xfd>
mov    0x8(%rbx),%rdi
mov    0x2d85(%rip),%rax
mov    (%rax),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <hexarg2binfile@plt>
xor    %ebx,%ebx
cmp    $0x4,%edi
jl     129a <main+0x12a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1090 <help@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
call   1060 <hexfile2binfile@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32* null
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [7 x i8] c"-stdin\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stdin
%12 = load i32*, i32** @stdout
%13 = call i32 @hexfile2binfile(i32 %11, i32* %12)
store i32 %13, i32* %3
br label %72
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %39
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%29 = call i64 @strncmp(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %24, %17
%32 = call i32 (...) @help()
store i32 %32, i32* %3
br label %72
33: ; preds = %24
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32*, i32** @stdout
%38 = call i32 @hexarg2binfile(i8* %36, i32* %37)
store i32 %38, i32* %3
br label %72
39: ; preds = %14
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 3
br i1 %41, label %42, label %67
42: ; preds = %39
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %46, i32** %7
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%51 = call i64 @strncmp(i8* %49, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %42
%54 = load i32, i32* @stdin
%55 = load i32*, i32** %7
%56 = call i32 @hexfile2binfile(i32 %54, i32* %55)
store i32 %56, i32* %6
br label %63
57: ; preds = %42
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = load i32*, i32** %7
%62 = call i32 @hexarg2binfile(i8* %60, i32* %61)
store i32 %62, i32* %6
br label %63
63: ; preds = %57, %53
%64 = load i32*, i32** %7
%65 = call i32 @fclose(i32* %64)
%66 = load i32, i32* %6
store i32 %66, i32* %3
br label %72
67: ; preds = %39
%68 = load i32, i32* %4
%69 = icmp sgt i32 %68, 3
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = call i32 (...) @help()
store i32 %71, i32* %3
br label %72
72: ; preds = %10, %31, %33, %63, %70, %67
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32* null
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [7 x i8] c"-stdin\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %42 [
i32 1, label %3
i32 2, label %7
i32 3, label %24
]
3: ; preds = %2
%4 = load i32, i32* @stdin
%5 = load i32*, i32** @stdout
%6 = tail call i32 @hexfile2binfile(i32 %4, i32* %5)
br label %46
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = tail call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %7
%14 = load i8*, i8** %8
%15 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13, %7
%19 = tail call i32 (...) @help()
br label %46
20: ; preds = %13
%21 = load i8*, i8** %8
%22 = load i32*, i32** @stdout
%23 = tail call i32 @hexarg2binfile(i8* %21, i32* %22)
br label %46
24: ; preds = %2
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%31 = tail call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = load i32, i32* @stdin
%35 = tail call i32 @hexfile2binfile(i32 %34, i32* %27)
br label %39
36: ; preds = %24
%37 = load i8*, i8** %28
%38 = tail call i32 @hexarg2binfile(i8* %37, i32* %27)
br label %39
39: ; preds = %36, %33
%40 = phi i32 [ %35, %33 ], [ %38, %36 ]
%41 = tail call i32 @fclose(i32* %27)
br label %46
42: ; preds = %2
%43 = icmp sgt i32 %0, 3
br i1 %43, label %44, label %46
44: ; preds = %42
%45 = tail call i32 (...) @help()
br label %46
46: ; preds = %42, %44, %39, %20, %18, %3
%47 = phi i32 [ %6, %3 ], [ %19, %18 ], [ %23, %20 ], [ %40, %39 ], [ %45, %44 ], [ 0, %42 ]
ret i32 %47
}