#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int sscanf(char *, char *, unsigned long *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char *, char *, int);
char *ulong_to_binary_string(unsigned long, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int argi;
  unsigned long x;
  char binary_buffer[128];
  if (argc < 2)
    usage(argv[0]);
  for (argi = 1; argi < argc; argi++) {
    if (strncmp(argv[argi], "0x", 2) == 0)
      argv[argi] += 2;
    else if (strncmp(argv[argi], "0X", 2) == 0)
      argv[argi] += 2;
    if (sscanf(argv[argi], "%lx", &x) == 1) {
      printf("%s\n", ulong_to_binary_string(x, binary_buffer));
    } else {
      fprintf(stderr, "Couldn't parse argument \"%s\" as hex integer.\n",
              argv[argi]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118f <main+0x2f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    129f <main+0x13f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11e2 <main+0x82>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x2,%rdx
mov    %rdx,(%rax,%rcx,8)
jmp    1222 <main+0xc2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe0e(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    121d <main+0xbd>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x2,%rdx
mov    %rdx,(%rax,%rcx,8)
jmp    1222 <main+0xc2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdd1(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    126b <main+0x10b>
mov    -0x20(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1080 <ulong_to_binary_string@plt>
mov    %rax,%rsi
lea    0xda9(%rip),%rdi
call   1040 <printf@plt>
jmp    128c <main+0x12c>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd87(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1291 <main+0x131>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1196 <main+0x36>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1195 <main+0x35>
mov    (%rbx),%rdi
call   1070 <usage@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edi,%r13d
mov    $0x1,%ebp
lea    0xe5c(%rip),%r14
lea    0xe5b(%rip),%r15
lea    0x8(%rsp),%r12
jmp    11e2 <main+0x82>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    (%rbx,%rbp,8),%rdx
lea    0xe3a(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     1181 <main+0x21>
mov    (%rbx,%rbp,8),%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
mov    (%rbx,%rbp,8),%rdi
test   %rax,%rax
je     1216 <main+0xb6>
lea    0xe00(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
mov    (%rbx,%rbp,8),%rdi
test   %rax,%rax
jne    121e <main+0xbe>
add    $0x2,%rdi
mov    %rdi,(%rbx,%rbp,8)
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11c0 <main+0x60>
mov    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1080 <ulong_to_binary_string@plt>
lea    0xdc6(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
jmp    11d9 <main+0x79>

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"0X\00"
@.str.2 = [4 x i8] c"%lx\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.4 = [46 x i8] c"Couldn't parse argument \22%s\22 as hex integer.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @usage(i8* %14)
br label %16
16: ; preds = %11, %2
store i32 1, i32* %6
br label %17
17: ; preds = %74, %16
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %77
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %21
%30 = load i8**, i8*** %5
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8, i8* %34, i64 2
store i8* %35, i8** %33
br label %52
36: ; preds = %21
%37 = load i8**, i8*** %5
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i64 @strncmp(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %36
%45 = load i8**, i8*** %5
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = getelementptr inbounds i8, i8* %49, i64 2
store i8* %50, i8** %48
br label %51
51: ; preds = %44, %36
br label %52
52: ; preds = %51, %29
%53 = load i8**, i8*** %5
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 @sscanf(i8* %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %7)
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %65
60: ; preds = %52
%61 = load i64, i64* %7
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%63 = call i8* @ulong_to_binary_string(i64 %61, i8* %62)
%64 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %63)
br label %73
65: ; preds = %52
%66 = load i32, i32* @stderr
%67 = load i8**, i8*** %5
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %71)
br label %73
73: ; preds = %65, %60
br label %74
74: ; preds = %73
%75 = load i32, i32* %6
%76 = add nsw i32 %75, 1
store i32 %76, i32* %6
br label %17
77: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"0X\00"
@.str.2 = [4 x i8] c"%lx\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.4 = [46 x i8] c"Couldn't parse argument \22%s\22 as hex integer.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca [128 x i8]
%5 = bitcast i64* %3 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 @usage(i8* %9)
br label %42
11: ; preds = %2
%12 = zext i32 %0 to i64
br label %13
13: ; preds = %11, %39
%14 = phi i64 [ 1, %11 ], [ %40, %39 ]
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%18 = icmp eq i64 %17, 0
%19 = load i8*, i8** %15
br i1 %18, label %24, label %20
20: ; preds = %13
%21 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%22 = icmp eq i64 %21, 0
%23 = load i8*, i8** %15
br i1 %22, label %24, label %27
24: ; preds = %20, %13
%25 = phi i8* [ %19, %13 ], [ %23, %20 ]
%26 = getelementptr inbounds i8, i8* %25, i64 2
store i8* %26, i8** %15
br label %27
27: ; preds = %24, %20
%28 = phi i8* [ %23, %20 ], [ %26, %24 ]
%29 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %3)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i64, i64* %3
%33 = call i8* @ulong_to_binary_string(i64 %32, i8* %6)
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %39
35: ; preds = %27
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %15
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %31, %35
%40 = add nuw nsw i64 %14, 1
%41 = icmp eq i64 %40, %12
br i1 %41, label %42, label %13
42: ; preds = %39, %8
ret i32 0
}