#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();
scalar_t__ isxdigit(char);
int /*<<< orphan*/ printf(char *, unsigned int);
int sscanf(char *, char *, unsigned int *);
unsigned int ask_for_base(unsigned int old) {
  unsigned int newone;
  char buf[1024];
  int count;
  int done = 0;
  do {
    printf("Please enter the base address or press enter for %X\n=>", old);
    count = 0;
    do {
      buf[count] = getchar();
      if ((isxdigit(buf[count]) == 0) && (buf[count] != '\n')) {
        buf[0] = 'x';
      }
      count++;
    } while ((buf[count - 1] != '\n') && (count < 1024));
    if (count == 1024) {
      count--;
      while (buf[count] != '\n') {
        buf[count] = getchar();
      }
    } else if (buf[0] == '\n') {
      newone = old;
      done = 1;
    } else if (sscanf(buf, "%x", &newone) == 1) {
      done = 1;
    }
  } while (!done);
  return newone;
}


x86 assembly (clang, -O0):
<ask_for_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x418(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x414(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,%cl
movslq -0x414(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
movslq -0x414(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%edi
ff
call   1060 <isxdigit@plt>
cmp    $0x0,%rax
jne    11c5 <ask_for_base+0x85>
movslq -0x414(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     11c5 <ask_for_base+0x85>
movb   $0x78,-0x410(%rbp)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%ecx
ff
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x419(%rbp)
je     120b <ask_for_base+0xcb>
cmpl   $0x400,-0x414(%rbp)
setl   %al
mov    %al,-0x419(%rbp)
mov    -0x419(%rbp),%al
test   $0x1,%al
jne    1171 <ask_for_base+0x31>
cmpl   $0x400,-0x414(%rbp)
jne    1271 <ask_for_base+0x131>
mov    -0x414(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x414(%rbp)
movslq -0x414(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     126c <ask_for_base+0x12c>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,%cl
movslq -0x414(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
jmp    1238 <ask_for_base+0xf8>
jmp    12ca <ask_for_base+0x18a>
movsbl -0x410(%rbp),%eax
cmp    $0xa,%eax
jne    1296 <ask_for_base+0x156>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x1,-0x418(%rbp)
jmp    12c5 <ask_for_base+0x185>
lea    -0x410(%rbp),%rdi
lea    0xd93(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    12c0 <ask_for_base+0x180>
movl   $0x1,-0x418(%rbp)
jmp    12c5 <ask_for_base+0x185>
jmp    12ca <ask_for_base+0x18a>
jmp    12cf <ask_for_base+0x18f>
cmpl   $0x0,-0x418(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1158 <ask_for_base+0x18>
mov    -0x8(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask_for_base>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %edi,%r13d
lea    0xea5(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13d,%esi
call   1030 <printf@plt>
xor    %r12d,%r12d
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
mov    %al,0x10(%rsp,%r12,1)
movsbl %al,%r15d
mov    %r15d,%edi
call   1060 <isxdigit@plt>
cmp    $0xa,%r15b
je     11a0 <ask_for_base+0x60>
test   %rax,%rax
jne    11a0 <ask_for_base+0x60>
movb   $0x78,0x10(%rsp)
movzbl 0x10(%rsp,%r12,1),%ebx
lea    0x1(%r12),%rbp
cmp    $0xa,%bl
je     11b6 <ask_for_base+0x76>
cmp    $0x3ff,%r12
mov    %rbp,%r12
jb     1170 <ask_for_base+0x30>
cmp    $0x400,%ebp
jne    11f0 <ask_for_base+0xb0>
cmp    $0xa,%bl
je     1160 <ask_for_base+0x20>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %al,0xf(%rsp,%rbp,1)
cmp    $0xa,%al
jne    11d0 <ask_for_base+0x90>
jmp    1160 <ask_for_base+0x20>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0xa,0x10(%rsp)
je     121b <ask_for_base+0xdb>
lea    0x10(%rsp),%rdi
lea    0xe34(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1160 <ask_for_base+0x20>
mov    0xc(%rsp),%r13d
mov    %r13d,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"Please enter the base address or press enter for %X\0A=>\00"
@.str.1 = [3 x i8] c"%x\00"
define i32 @ask_for_base(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %6
br label %7
7: ; preds = %80, %1
%8 = load i32, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 0, i32* %5
br label %10
10: ; preds = %44, %7
%11 = call signext i8 (...) @getchar()
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %13
store i8 %11, i8* %14
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = call i64 @isxdigit(i8 signext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %10
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 10
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i8 120, i8* %29
br label %30
30: ; preds = %28, %21, %10
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %33
33: ; preds = %30
%34 = load i32, i32* %5
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 10
br i1 %40, label %41, label %44
41: ; preds = %33
%42 = load i32, i32* %5
%43 = icmp slt i32 %42, 1024
br label %44
44: ; preds = %41, %33
%45 = phi i1 [ false, %33 ], [ %43, %41 ]
br i1 %45, label %10, label %46
46: ; preds = %44
%47 = load i32, i32* %5
%48 = icmp eq i32 %47, 1024
br i1 %48, label %49, label %65
49: ; preds = %46
%50 = load i32, i32* %5
%51 = add nsw i32 %50, -1
store i32 %51, i32* %5
br label %52
52: ; preds = %59, %49
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 10
br i1 %58, label %59, label %64
59: ; preds = %52
%60 = call signext i8 (...) @getchar()
%61 = load i32, i32* %5
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %62
store i8 %60, i8* %63
br label %52
64: ; preds = %52
br label %79
65: ; preds = %46
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 10
br i1 %69, label %70, label %72
70: ; preds = %65
%71 = load i32, i32* %2
store i32 %71, i32* %3
store i32 1, i32* %6
br label %78
72: ; preds = %65
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%74 = call i32 @sscanf(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%75 = icmp eq i32 %74, 1
br i1 %75, label %76, label %77
76: ; preds = %72
store i32 1, i32* %6
br label %77
77: ; preds = %76, %72
br label %78
78: ; preds = %77, %70
br label %79
79: ; preds = %78, %64
br label %80
80: ; preds = %79
%81 = load i32, i32* %6
%82 = icmp ne i32 %81, 0
%83 = xor i1 %82, true
br i1 %83, label %7, label %84
84: ; preds = %80
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@.str = [55 x i8] c"Please enter the base address or press enter for %X\0A=>\00"
@.str.1 = [3 x i8] c"%x\00"
define i32 @ask_for_base(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %6
6: ; preds = %29, %1
%7 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %8
8: ; preds = %18, %6
%9 = phi i64 [ %20, %18 ], [ 0, %6 ]
%10 = call signext i8 (...) @getchar()
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %9
store i8 %10, i8* %11
%12 = call i64 @isxdigit(i8 signext %10)
%13 = icmp ne i64 %12, 0
%14 = icmp eq i8 %10, 10
%15 = or i1 %14, %13
br i1 %15, label %18, label %16
16: ; preds = %8
store i8 120, i8* %5
%17 = load i8, i8* %11
br label %18
18: ; preds = %16, %8
%19 = phi i8 [ %17, %16 ], [ %10, %8 ]
%20 = add nuw nsw i64 %9, 1
%21 = icmp ne i8 %19, 10
%22 = icmp ult i64 %9, 1023
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %8, label %24
24: ; preds = %18
%25 = trunc i64 %20 to i32
%26 = icmp eq i32 %25, 1024
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = icmp eq i8 %19, 10
br i1 %28, label %29, label %30
29: ; preds = %30, %27, %36
br label %6
30: ; preds = %27, %30
%31 = call signext i8 (...) @getchar()
store i8 %31, i8* %11
%32 = icmp eq i8 %31, 10
br i1 %32, label %29, label %30
33: ; preds = %24
%34 = load i8, i8* %5
%35 = icmp eq i8 %34, 10
br i1 %35, label %41, label %36
36: ; preds = %33
%37 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %29
39: ; preds = %36
%40 = load i32, i32* %2
br label %41
41: ; preds = %33, %39
%42 = phi i32 [ %40, %39 ], [ %0, %33 ]
ret i32 %42
}