#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 */
long htoi(char *);
int /*<<< orphan*/ printf(char *, char *, long);
long strtol(char *, char **, int);
int main(void) {
  char *endp = NULL;
  char *test[] = {"F00",    "bar",    "0100",     "0x1",      "0XA",  "0X0C0BE",
                  "abcdef", "123456", "0x123456", "deadbeef", "zog_c"};
  long int result;
  long int check;
  size_t numtests = sizeof test / sizeof test[0];
  size_t thistest;
  for (thistest = 0; thistest < numtests; thistest++) {
    result = htoi(test[thistest]);
    check = strtol(test[thistest], &endp, 16);
    if ((*endp != '\0' && result == -1) || result == check) {
      printf("Testing %s. Correct. %ld\n", test[thistest], result);
    } else {
      printf("Testing %s. Incorrect. %ld\n", test[thistest], result);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
lea    0x2c5b(%rip),%rsi
mov    $0x58,%edx
call   1050 <memcpy@plt>
movq   $0xb,-0x88(%rbp)
movq   $0x0,-0x90(%rbp)
mov    -0x90(%rbp),%rax
cmp    -0x88(%rbp),%rax
jae    124e <main+0x10e>
mov    -0x90(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1060 <htoi@plt>
mov    %rax,-0x78(%rbp)
mov    -0x90(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e7 <main+0xa7>
cmpq   $0xffffffffffffffff,-0x78(%rbp)
je     11f5 <main+0xb5>
mov    -0x78(%rbp),%rax
cmp    -0x80(%rbp),%rax
jne    1216 <main+0xd6>
mov    -0x90(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x78(%rbp),%rdx
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
jmp    1232 <main+0xf2>
mov    -0x90(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x78(%rbp),%rdx
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
jmp    1237 <main+0xf7>
mov    -0x90(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x90(%rbp)
jmp    1185 <main+0x45>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movq   $0x0,(%rsp)
xor    %ebx,%ebx
lea    0x2c74(%rip),%r13
mov    %rsp,%r14
lea    0xee6(%rip),%rbp
jmp    118b <main+0x5b>
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rax
cmp    $0xffffffffffffffff,%r12
mov    %rcx,%rdi
cmove  %rbp,%rdi
cmpb   $0x0,(%rax)
cmove  %rcx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <printf@plt>
add    $0x8,%rbx
cmp    $0x58,%rbx
je     11bb <main+0x8b>
mov    (%rbx,%r13,1),%r15
mov    %r15,%rdi
call   1050 <htoi@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rbp,%rcx
cmp    %rax,%r12
je     1160 <main+0x30>
lea    0xe9d(%rip),%rcx
jmp    1160 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"F00\00"
@.str.1 = [4 x i8] c"bar\00"
@.str.2 = [5 x i8] c"0100\00"
@.str.3 = [4 x i8] c"0x1\00"
@.str.4 = [4 x i8] c"0XA\00"
@.str.5 = [8 x i8] c"0X0C0BE\00"
@.str.6 = [7 x i8] c"abcdef\00"
@.str.7 = [7 x i8] c"123456\00"
@.str.8 = [9 x i8] c"0x123456\00"
@.str.9 = [9 x i8] c"deadbeef\00"
@.str.10 = [6 x i8] c"zog_c\00"
@__const.main.test = [11 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i32 0, i32 0)]
@.str.11 = [26 x i8] c"Testing %s. Correct. %ld\0A\00"
@.str.12 = [28 x i8] c"Testing %s. Incorrect. %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [11 x i8*]
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
store i8* null, i8** %2
%8 = bitcast [11 x i8*]* %3 to i8*
store i64 11, i64* %6
store i64 0, i64* %7
br label %9
9: ; preds = %46, %0
%10 = load i64, i64* %7
%11 = load i64, i64* %6
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %49
13: ; preds = %9
%14 = load i64, i64* %7
%15 = getelementptr inbounds [11 x i8*], [11 x i8*]* %3, i64 0, i64 %14
%16 = load i8*, i8** %15
%17 = call i64 @htoi(i8* %16)
store i64 %17, i64* %4
%18 = load i64, i64* %7
%19 = getelementptr inbounds [11 x i8*], [11 x i8*]* %3, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = call i64 @strtol(i8* %20, i8** %2, i32 16)
store i64 %21, i64* %5
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %13
%27 = load i64, i64* %4
%28 = icmp eq i64 %27, -1
br i1 %28, label %33, label %29
29: ; preds = %26, %13
%30 = load i64, i64* %4
%31 = load i64, i64* %5
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %39
33: ; preds = %29, %26
%34 = load i64, i64* %7
%35 = getelementptr inbounds [11 x i8*], [11 x i8*]* %3, i64 0, i64 %34
%36 = load i8*, i8** %35
%37 = load i64, i64* %4
%38 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* %36, i64 %37)
br label %45
39: ; preds = %29
%40 = load i64, i64* %7
%41 = getelementptr inbounds [11 x i8*], [11 x i8*]* %3, i64 0, i64 %40
%42 = load i8*, i8** %41
%43 = load i64, i64* %4
%44 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i8* %42, i64 %43)
br label %45
45: ; preds = %39, %33
br label %46
46: ; preds = %45
%47 = load i64, i64* %7
%48 = add i64 %47, 1
store i64 %48, i64* %7
br label %9
49: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"F00\00"
@.str.1 = [4 x i8] c"bar\00"
@.str.2 = [5 x i8] c"0100\00"
@.str.3 = [4 x i8] c"0x1\00"
@.str.4 = [4 x i8] c"0XA\00"
@.str.5 = [8 x i8] c"0X0C0BE\00"
@.str.6 = [7 x i8] c"abcdef\00"
@.str.7 = [7 x i8] c"123456\00"
@.str.8 = [9 x i8] c"0x123456\00"
@.str.9 = [9 x i8] c"deadbeef\00"
@.str.10 = [6 x i8] c"zog_c\00"
@__const.main.test = [11 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i32 0, i32 0)]
@.str.11 = [26 x i8] c"Testing %s. Correct. %ld\0A\00"
@.str.12 = [28 x i8] c"Testing %s. Incorrect. %ld\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
store i8* null, i8** %1
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %18, %3 ]
%5 = getelementptr inbounds [11 x i8*], [11 x i8*]* @__const.main.test, i64 0, i64 %4
%6 = load i8*, i8** %5
%7 = tail call i64 @htoi(i8* %6)
%8 = call i64 @strtol(i8* %6, i8** %1, i32 16)
%9 = load i8*, i8** %1
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
%12 = icmp eq i64 %7, -1
%13 = and i1 %11, %12
%14 = icmp eq i64 %7, %8
%15 = select i1 %13, i1 true, i1 %14
%16 = select i1 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0)
%17 = tail call i32 @printf(i8* %16, i8* %6, i64 %7)
%18 = add nuw nsw i64 %4, 1
%19 = icmp eq i64 %18, 11
br i1 %19, label %20, label %3
20: ; preds = %3
ret i32 0
}