#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 */
unsigned int htoi(char *);
int /*<<< orphan*/ printf(char *, char *, unsigned int);
scalar_t__ strtoul(char *, char **, int);
int main(void) {
  char *endp = NULL;
  char *test[] = {"F00",    "bar",    "0100",     "0x1",      "0XA",  "0X0C0BE",
                  "abcdef", "123456", "0x123456", "deadbeef", "zog_c"};
  unsigned int result;
  unsigned int check;
  size_t numtests = sizeof test / sizeof test[0];
  size_t thistest;
  for (thistest = 0; thistest < numtests; thistest++) {
    result = htoi(test[thistest]);
    check = (unsigned int)strtoul(test[thistest], &endp, 16);
    if ((*endp != '\0' && result == 0) || result == check) {
      printf("Testing %s. Correct. %u\n", test[thistest], result);
    } else {
      printf("Testing %s. Incorrect. %u\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   1040 <memcpy@plt>
movq   $0xb,-0x80(%rbp)
movq   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%rax
cmp    -0x80(%rbp),%rax
jae    1241 <main+0x101>
mov    -0x88(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
call   1050 <htoi@plt>
mov    %eax,-0x74(%rbp)
mov    -0x88(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x78(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11de <main+0x9e>
cmpl   $0x0,-0x74(%rbp)
je     11ea <main+0xaa>
mov    -0x74(%rbp),%eax
cmp    -0x78(%rbp),%eax
jne    120a <main+0xca>
mov    -0x88(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x74(%rbp),%edx
lea    0xe3c(%rip),%rdi
call   1030 <printf@plt>
jmp    1225 <main+0xe5>
mov    -0x88(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rsi
mov    -0x74(%rbp),%edx
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
jmp    122a <main+0xea>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
jmp    1182 <main+0x42>
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),%r12
mov    %rsp,%r14
lea    0xee6(%rip),%r13
jmp    1188 <main+0x58>
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rax
test   %ebp,%ebp
mov    %rcx,%rdi
cmove  %r13,%rdi
cmpb   $0x0,(%rax)
cmove  %rcx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <printf@plt>
add    $0x8,%rbx
cmp    $0x58,%rbx
je     11b6 <main+0x86>
mov    (%rbx,%r12,1),%r15
mov    %r15,%rdi
call   1040 <htoi@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %r13,%rcx
cmp    %eax,%ebp
je     1160 <main+0x30>
lea    0xea1(%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 = [25 x i8] c"Testing %s. Correct. %u\0A\00"
@.str.12 = [27 x i8] c"Testing %s. Incorrect. %u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [11 x i8*]
%4 = alloca i32
%5 = alloca i32
%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 = %47, %0
%10 = load i64, i64* %7
%11 = load i64, i64* %6
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %50
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 i32 @htoi(i8* %16)
store i32 %17, i32* %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 @strtoul(i8* %20, i8** %2, i32 16)
%22 = trunc i64 %21 to i32
store i32 %22, i32* %5
%23 = load i8*, i8** %2
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %13
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27, %13
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %40
34: ; preds = %30, %27
%35 = load i64, i64* %7
%36 = getelementptr inbounds [11 x i8*], [11 x i8*]* %3, i64 0, i64 %35
%37 = load i8*, i8** %36
%38 = load i32, i32* %4
%39 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i8* %37, i32 %38)
br label %46
40: ; preds = %30
%41 = load i64, i64* %7
%42 = getelementptr inbounds [11 x i8*], [11 x i8*]* %3, i64 0, i64 %41
%43 = load i8*, i8** %42
%44 = load i32, i32* %4
%45 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0), i8* %43, i32 %44)
br label %46
46: ; preds = %40, %34
br label %47
47: ; preds = %46
%48 = load i64, i64* %7
%49 = add i64 %48, 1
store i64 %49, i64* %7
br label %9
50: ; 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 = [25 x i8] c"Testing %s. Correct. %u\0A\00"
@.str.12 = [27 x i8] c"Testing %s. Incorrect. %u\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 ], [ %19, %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 i32 @htoi(i8* %6)
%8 = call i64 @strtoul(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 i32 %7, 0
%13 = and i1 %11, %12
%14 = trunc i64 %8 to i32
%15 = icmp eq i32 %7, %14
%16 = select i1 %13, i1 true, i1 %15
%17 = select i1 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.12, i64 0, i64 0)
%18 = tail call i32 @printf(i8* %17, i8* %6, i32 %7)
%19 = add nuw nsw i64 %4, 1
%20 = icmp eq i64 %19, 11
br i1 %20, label %21, label %3
21: ; preds = %3
ret i32 0
}