#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 getchar();
int getlinee(char *, int);
int /*<<< orphan*/ htoi(char *, int);
int /*<<< orphan*/ printf(char *);
int main() {
  int i, j, c;
  j = 0;
  i = 0;
  char line[1000];
  printf("Welcome to the HEX to INT converter\nPlease enter a hexadecimal "
         "number\n");
  while (1) {
    if (j != 0) {
      printf("Do you want to continue(Y\\N)?");
      if (((c = getchar()) == 'Y') || (c == 'y')) {
        printf("\nPlease enter a hexadecimal number\n");
        c = getchar();
        i = getlinee(line, 1000);
        if (i >= 0) {
          htoi(line, i);
        }
      } else if ((c == 'N') || (c == 'n'))
        break;
      else
        printf("I don't understand that command\n");
    } else {
      i = getlinee(line, 1000);
      if (i >= 0) {
        htoi(line, i);
        j = 1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
je     1216 <main+0xd6>
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x59,%eax
je     119f <main+0x5f>
cmpl   $0x79,-0x10(%rbp)
jne    11e7 <main+0xa7>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1060 <getlinee@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11e2 <main+0xa2>
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <htoi@plt>
jmp    1211 <main+0xd1>
cmpl   $0x4e,-0x10(%rbp)
je     11fb <main+0xbb>
cmpl   $0x6e,-0x10(%rbp)
jne    1200 <main+0xc0>
jmp    1254 <main+0x114>
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
jmp    1211 <main+0xd1>
jmp    124f <main+0x10f>
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1060 <getlinee@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     124a <main+0x10a>
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <htoi@plt>
movl   $0x1,-0xc(%rbp)
jmp    124f <main+0x10f>
jmp    116c <main+0x2c>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3e8,%rsp
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1070 <getlinee@plt>
test   %eax,%eax
js     1170 <main+0x20>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <htoi@plt>
lea    0xe6b(%rip),%rbx
lea    0xea5(%rip),%r15
lea    0xec1(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
and    $0xffffffdf,%eax
cmp    $0x59,%eax
je     11e0 <main+0x90>
cmp    $0x4e,%eax
je     120c <main+0xbc>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    11b0 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %r14,%rdi
mov    $0x3e8,%esi
call   1070 <getlinee@plt>
test   %eax,%eax
js     11b0 <main+0x60>
mov    %r14,%rdi
mov    %eax,%esi
call   1060 <htoi@plt>
jmp    11b0 <main+0x60>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [71 x i8] c"Welcome to the HEX to INT converter\0APlease enter a hexadecimal number\0A\00"
@.str.1 = [30 x i8] c"Do you want to continue(Y\\N)?\00"
@.str.2 = [36 x i8] c"\0APlease enter a hexadecimal number\0A\00"
@.str.3 = [33 x i8] c"I don't understand that command\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %2
%6 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %0, %50
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %40
10: ; preds = %7
%11 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (...) @getchar()
store i32 %12, i32* %4
%13 = icmp eq i32 %12, 89
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 121
br i1 %16, label %17, label %29
17: ; preds = %14, %10
%18 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 (...) @getchar()
store i32 %19, i32* %4
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%21 = call i32 @getlinee(i8* %20, i32 1000)
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%26 = load i32, i32* %2
%27 = call i32 @htoi(i8* %25, i32 %26)
br label %28
28: ; preds = %24, %17
br label %39
29: ; preds = %14
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 78
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 110
br i1 %34, label %35, label %36
35: ; preds = %32, %29
br label %51
36: ; preds = %32
%37 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36
br label %39
39: ; preds = %38, %28
br label %50
40: ; preds = %7
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%42 = call i32 @getlinee(i8* %41, i32 1000)
store i32 %42, i32* %2
%43 = load i32, i32* %2
%44 = icmp sge i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %40
%46 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%47 = load i32, i32* %2
%48 = call i32 @htoi(i8* %46, i32 %47)
store i32 1, i32* %3
br label %49
49: ; preds = %45, %40
br label %50
50: ; preds = %49, %39
br label %7
51: ; preds = %35
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"Do you want to continue(Y\\N)?\00"
@str = [70 x i8] c"Welcome to the HEX to INT converter\0APlease enter a hexadecimal number\00"
@str.4 = [32 x i8] c"I don't understand that command\00"
@str.5 = [35 x i8] c"\0APlease enter a hexadecimal number\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str, i64 0, i64 0))
br label %17
4: ; preds = %8, %20, %15, %13
%5 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 (...) @getchar()
%7 = and i32 %6, -33
switch i32 %7, label %15 [
i32 89, label %8
i32 78, label %22
]
8: ; preds = %4
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.5, i64 0, i64 0))
%10 = call i32 (...) @getchar()
%11 = call i32 @getlinee(i8* %2, i32 1000)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %4
13: ; preds = %8
%14 = call i32 @htoi(i8* %2, i32 %11)
br label %4
15: ; preds = %4
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.4, i64 0, i64 0))
br label %4
17: ; preds = %17, %0
%18 = call i32 @getlinee(i8* %2, i32 1000)
%19 = icmp sgt i32 %18, -1
br i1 %19, label %20, label %17
20: ; preds = %17
%21 = call i32 @htoi(i8* %2, i32 %18)
br label %4
22: ; preds = %4
ret i32 0
}