#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 *, unsigned long);
int sscanf(char *, char *, unsigned long *);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int argi;
  unsigned long x;
  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("%lu\n", x);
    } 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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    117c <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127d <main+0x12d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11cf <main+0x7f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x2,%rdx
mov    %rdx,(%rax,%rcx,8)
jmp    120f <main+0xbf>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe21(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    120a <main+0xba>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
add    $0x2,%rdx
mov    %rdx,(%rax,%rcx,8)
jmp    120f <main+0xbf>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xde4(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1249 <main+0xf9>
mov    -0x20(%rbp),%rsi
lea    0xdcb(%rip),%rdi
call   1040 <printf@plt>
jmp    126a <main+0x11a>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdaa(%rip),%rsi
call   1050 <fprintf@plt>
jmp    126f <main+0x11f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1183 <main+0x33>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     117c <main+0x2c>
mov    (%rbx),%rdi
call   1070 <usage@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edi,%ebp
mov    $0x1,%r13d
lea    0xe75(%rip),%r14
lea    0xe74(%rip),%r15
mov    %rsp,%r12
jmp    11c2 <main+0x72>
nopw   0x0(%rax,%rax,1)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    (%rbx,%r13,8),%rdx
lea    0xe5b(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%rbp
je     116b <main+0x1b>
mov    (%rbx,%r13,8),%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
mov    (%rbx,%r13,8),%rdi
test   %rax,%rax
je     11f6 <main+0xa6>
lea    0xe20(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
mov    (%rbx,%r13,8),%rdi
test   %rax,%rax
jne    11fe <main+0xae>
add    $0x2,%rdi
mov    %rdi,(%rbx,%r13,8)
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11a0 <main+0x50>
mov    (%rsp),%rsi
lea    0xdf1(%rip),%rdi
call   1040 <printf@plt>
jmp    11b9 <main+0x69>

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 = [5 x i8] c"%lu\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @usage(i8* %13)
br label %15
15: ; preds = %10, %2
store i32 1, i32* %6
br label %16
16: ; preds = %71, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %74
20: ; preds = %16
%21 = load i8**, i8*** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %20
%29 = load i8**, i8*** %5
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8* %34, i8** %32
br label %51
35: ; preds = %20
%36 = load i8**, i8*** %5
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i64 @strncmp(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %35
%44 = load i8**, i8*** %5
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = getelementptr inbounds i8, i8* %48, i64 2
store i8* %49, i8** %47
br label %50
50: ; preds = %43, %35
br label %51
51: ; preds = %50, %28
%52 = load i8**, i8*** %5
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 @sscanf(i8* %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %7)
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %62
59: ; preds = %51
%60 = load i64, i64* %7
%61 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %60)
br label %70
62: ; preds = %51
%63 = load i32, i32* @stderr
%64 = load i8**, i8*** %5
%65 = load i32, i32* %6
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %62, %59
br label %71
71: ; preds = %70
%72 = load i32, i32* %6
%73 = add nsw i32 %72, 1
store i32 %73, i32* %6
br label %16
74: ; preds = %16
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 = [5 x i8] c"%lu\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 = bitcast i64* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %39
9: ; preds = %2
%10 = zext i32 %0 to i64
br label %11
11: ; preds = %9, %36
%12 = phi i64 [ 1, %9 ], [ %37, %36 ]
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i8*, i8** %13
%15 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%16 = icmp eq i64 %15, 0
%17 = load i8*, i8** %13
br i1 %16, label %22, label %18
18: ; preds = %11
%19 = call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%20 = icmp eq i64 %19, 0
%21 = load i8*, i8** %13
br i1 %20, label %22, label %25
22: ; preds = %18, %11
%23 = phi i8* [ %17, %11 ], [ %21, %18 ]
%24 = getelementptr inbounds i8, i8* %23, i64 2
store i8* %24, i8** %13
br label %25
25: ; preds = %22, %18
%26 = phi i8* [ %21, %18 ], [ %24, %22 ]
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %3)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i64, i64* %3
%31 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %30)
br label %36
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %13
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %29, %32
%37 = add nuw nsw i64 %12, 1
%38 = icmp eq i64 %37, %10
br i1 %38, label %39, label %11
39: ; preds = %36, %6
ret i32 0
}