#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 htoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int i;
  char a[8];
  for (i = 0; i < 8; i++)
    a[i] = 0;
  a[0] = '0';
  a[1] = 'x';
  a[2] = '5';
  a[3] = 'b';
  a[4] = 'f';
  a[5] = 'c';
  a[6] = 'd';
  a[7] = 'a';
  printf("\nConvert a hex string to integer (8 characters max).\n\n");
  for (i = 0; i < 8 && a[i] != 0; i++)
    printf("%c", a[i]);
  printf(" in hex is %u in decimal.\n\n", htoi(a));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    1157 <main+0x37>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x10(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <main+0x16>
movb   $0x30,-0x10(%rbp)
movb   $0x78,-0xf(%rbp)
movb   $0x35,-0xe(%rbp)
movb   $0x62,-0xd(%rbp)
movb   $0x66,-0xc(%rbp)
movb   $0x63,-0xb(%rbp)
movb   $0x64,-0xa(%rbp)
movb   $0x61,-0x9(%rbp)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x8,-0x8(%rbp)
mov    %al,-0x11(%rbp)
jge    11ad <main+0x8d>
movslq -0x8(%rbp),%rax
movsbl -0x10(%rbp,%rax,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11bd <main+0x9d>
jmp    11e2 <main+0xc2>
movslq -0x8(%rbp),%rax
movsbl -0x10(%rbp,%rax,1),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118c <main+0x6c>
lea    -0x10(%rbp),%rdi
call   1040 <htoi@plt>
mov    %eax,%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movabs $0x6164636662357830,%rax
63 64 61
mov    %rax,(%rsp)
lea    0xec6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x30,%edi
call   1030 <putchar@plt>
mov    $0x78,%edi
call   1030 <putchar@plt>
mov    $0x35,%edi
call   1030 <putchar@plt>
mov    $0x62,%edi
call   1030 <putchar@plt>
mov    $0x66,%edi
call   1030 <putchar@plt>
mov    $0x63,%edi
call   1030 <putchar@plt>
mov    $0x64,%edi
call   1030 <putchar@plt>
mov    $0x61,%edi
call   1030 <putchar@plt>
mov    %rsp,%rdi
call   1060 <htoi@plt>
lea    0xe46(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [55 x i8] c"\0AConvert a hex string to integer (8 characters max).\0A\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [28 x i8] c" in hex is %u in decimal.\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [8 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
br label %4
4: ; preds = %11, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 8
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %9
store i8 0, i8* %10
br label %11
11: ; preds = %7
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
store i32 %13, i32* %2
br label %4
14: ; preds = %4
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
store i8 48, i8* %15
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
store i8 120, i8* %16
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 2
store i8 53, i8* %17
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 3
store i8 98, i8* %18
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 4
store i8 102, i8* %19
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 5
store i8 99, i8* %20
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 6
store i8 100, i8* %21
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
store i8 97, i8* %22
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %24
24: ; preds = %43, %14
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 8
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br label %34
34: ; preds = %27, %24
%35 = phi i1 [ false, %24 ], [ %33, %27 ]
br i1 %35, label %36, label %46
36: ; preds = %34
%37 = load i32, i32* %2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %36
%44 = load i32, i32* %2
%45 = add nsw i32 %44, 1
store i32 %45, i32* %2
br label %24
46: ; preds = %34
%47 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%48 = call i32 @htoi(i8* %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %48)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [28 x i8] c" in hex is %u in decimal.\0A\0A\00"
@str = [54 x i8] c"\0AConvert a hex string to integer (8 characters max).\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
store i64 7017843410735560752, i64* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @putchar(i32 48)
%5 = tail call i32 @putchar(i32 120)
%6 = tail call i32 @putchar(i32 53)
%7 = tail call i32 @putchar(i32 98)
%8 = tail call i32 @putchar(i32 102)
%9 = tail call i32 @putchar(i32 99)
%10 = tail call i32 @putchar(i32 100)
%11 = tail call i32 @putchar(i32 97)
%12 = call i32 @htoi(i8* %2)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %12)
ret i32 0
}