#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 */
scalar_t__ hex2int(char const *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int i;
  const char *str[] = {"cc", "e8", "cf", "7f", NULL};
  for (i = 0; str[i]; ++i) {
    int result;
    if (hex2int(str[i], &result) == 0)
      printf("%s -> %d\n", str[i], result);
    else
      printf("convert error.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    0xeaa(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xea2(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe92(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
cmpq   $0x0,-0x30(%rbp,%rax,8)
je     11ee <main+0xbe>
movslq -0x8(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
lea    -0x34(%rbp),%rsi
call   1040 <hex2int@plt>
cmp    $0x0,%rax
jne    11cd <main+0x9d>
movslq -0x8(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
mov    -0x34(%rbp),%edx
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11db <main+0xab>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e0 <main+0xb0>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1182 <main+0x52>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
movq   $0x0,0x30(%rsp)
lea    0xeb3(%rip),%r13
mov    %r13,0x10(%rsp)
lea    0x18(%rsp),%rbx
lea    0xea5(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe9c(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe93(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xc(%rsp),%r12
lea    0xe85(%rip),%r14
lea    0xe88(%rip),%r15
jmp    11a4 <main+0x74>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    (%rbx),%r13
add    $0x8,%rbx
test   %r13,%r13
je     11c7 <main+0x97>
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <hex2int@plt>
test   %rax,%rax
jne    1190 <main+0x60>
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1198 <main+0x68>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"cc\00"
@.str.1 = [3 x i8] c"e8\00"
@.str.2 = [3 x i8] c"cf\00"
@.str.3 = [3 x i8] c"7f\00"
@.str.4 = [10 x i8] c"%s -> %d\0A\00"
@.str.5 = [16 x i8] c"convert error.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [5 x i8*]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [5 x i8*]* %3 to i8*
%6 = bitcast i8* %5 to [5 x i8*]*
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8** %10
store i32 0, i32* %2
br label %11
11: ; preds = %34, %0
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %37
17: ; preds = %11
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %19
%21 = load i8*, i8** %20
%22 = call i64 @hex2int(i8* %21, i32* %4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %17
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = load i32, i32* %4
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %28, i32 %29)
br label %33
31: ; preds = %17
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %33
33: ; preds = %31, %24
br label %34
34: ; preds = %33
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
br label %11
37: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"cc\00"
@.str.1 = [3 x i8] c"e8\00"
@.str.2 = [3 x i8] c"cf\00"
@.str.3 = [3 x i8] c"7f\00"
@.str.4 = [10 x i8] c"%s -> %d\0A\00"
@str = [15 x i8] c"convert error.\00"
define i32 @main() {
%1 = alloca [5 x i8*]
%2 = alloca i32
%3 = bitcast [5 x i8*]* %1 to i8*
%4 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 4
%5 = bitcast i8** %4 to i64*
store i64 0, i64* %5
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %9
%10 = bitcast i32* %2 to i8*
br label %11
11: ; preds = %0, %21
%12 = phi i64 [ 0, %0 ], [ %22, %21 ]
%13 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %0 ], [ %24, %21 ]
%14 = call i64 @hex2int(i8* %13, i32* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %2
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %13, i32 %17)
br label %21
19: ; preds = %11
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = add nuw i64 %12, 1
%23 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %22
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %11
26: ; preds = %21
ret i32 0
}