#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 */
char getchar();
int htoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int i;
  char c, hexstring[100];
  printf("Input hexadecimal:\n");
  for (i = 0; (c = getchar()) != '\n' && i < 100; i++) {
    hexstring[i] = c;
  }
  hexstring[i] = '\0';
  int translation = htoi(hexstring);
  printf("The hex string : %s is equal to : %d\n", hexstring, translation);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x75(%rbp)
je     117c <main+0x4c>
cmpl   $0x64,-0x8(%rbp)
setl   %al
mov    %al,-0x75(%rbp)
mov    -0x75(%rbp),%al
test   $0x1,%al
jne    118c <main+0x5c>
jmp    11a5 <main+0x75>
mov    -0x9(%rbp),%cl
movslq -0x8(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1157 <main+0x27>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rdi
call   1050 <htoi@plt>
mov    %eax,-0x74(%rbp)
lea    -0x70(%rbp),%rsi
mov    -0x74(%rbp),%edx
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     118b <main+0x4b>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %al,(%rsp,%rbx,1)
lea    0x1(%rbx),%r14
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     118b <main+0x4b>
cmp    $0x63,%rbx
mov    %r14,%rbx
jb     1170 <main+0x30>
movb   $0x0,(%rsp,%r14,1)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <htoi@plt>
lea    0xe5e(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Input hexadecimal:\0A\00"
@.str.1 = [38 x i8] c"The hex string : %s is equal to : %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca [100 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %7
7: ; preds = %21, %0
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %3
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 100
br label %14
14: ; preds = %11, %7
%15 = phi i1 [ false, %7 ], [ %13, %11 ]
br i1 %15, label %16, label %24
16: ; preds = %14
%17 = load i8, i8* %3
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %19
store i8 %17, i8* %20
br label %21
21: ; preds = %16
%22 = load i32, i32* %2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %2
br label %7
24: ; preds = %14
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %26
store i8 0, i8* %27
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%29 = call i32 @htoi(i8* %28)
store i32 %29, i32* %5
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%31 = load i32, i32* %5
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %30, i32 %31)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [38 x i8] c"The hex string : %s is equal to : %d\0A\00"
@str = [19 x i8] c"Input hexadecimal:\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = tail call signext i8 (...) @getchar()
%5 = icmp eq i8 %4, 10
br i1 %5, label %15, label %6
6: ; preds = %0, %6
%7 = phi i64 [ %10, %6 ], [ 0, %0 ]
%8 = phi i8 [ %11, %6 ], [ %4, %0 ]
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %7
store i8 %8, i8* %9
%10 = add nuw nsw i64 %7, 1
%11 = tail call signext i8 (...) @getchar()
%12 = icmp ne i8 %11, 10
%13 = icmp ult i64 %7, 99
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %6, label %15
15: ; preds = %6, %0
%16 = phi i64 [ 0, %0 ], [ %10, %6 ]
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @htoi(i8* %2)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %18)
ret i32 0
}