#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 */
unsigned long atox(char *, int *);
char c40_getchar();
int /*<<< orphan*/ c40_printf(char *, ...);
char c40_putchar(char);
unsigned long get_addr(char *str) {
  char in_char, in_line[9] = {'\0'};
  int i, ok = 0;
  unsigned long addr;
  while (!ok) {
    c40_printf("\n");
    c40_printf("%s Address => ", str);
    ok = 1;
    i = 0;
    while ((c40_putchar((in_char = c40_getchar()))) != '\n') {
      if (in_char == '\b') {
        if (i)
          i--;
      } else if (in_char == 0xd)
        continue;
      else
        in_line[i++] = in_char;
      if (i > 8) {
        c40_printf("\nLine too long.\n");
        ok = 0;
        break;
      }
    }
    in_line[i] = '\0';
    if (!ok)
      continue;
    if (i == 0)
      return (0);
    ok = 1;
    addr = atox(in_line, &ok);
    if (ok == 0)
      c40_printf("Not a valid number : %s\n", in_line);
    else
      return (addr);
  }
}


x86 assembly (clang, -O0):
<get_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x1a(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1050 <memset@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1189 <get_addr+0x39>
jmp    12c8 <get_addr+0x178>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1070 <c40_printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1070 <c40_printf@plt>
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <c40_getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%edi
call   1060 <c40_putchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     124e <get_addr+0xfe>
movsbl -0x11(%rbp),%eax
cmp    $0x8,%eax
jne    11fa <get_addr+0xaa>
cmpl   $0x0,-0x20(%rbp)
je     11f5 <get_addr+0xa5>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1225 <get_addr+0xd5>
movsbl -0x11(%rbp),%eax
cmp    $0xd,%eax
jne    120c <get_addr+0xbc>
jmp    11b7 <get_addr+0x67>
mov    -0x11(%rbp),%cl
mov    -0x20(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
cltq
mov    %cl,-0x1a(%rbp,%rax,1)
jmp    1225 <get_addr+0xd5>
cmpl   $0x8,-0x20(%rbp)
jle    1249 <get_addr+0xf9>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1070 <c40_printf@plt>
movl   $0x0,-0x24(%rbp)
jmp    124e <get_addr+0xfe>
jmp    11b7 <get_addr+0x67>
movslq -0x20(%rbp),%rax
movb   $0x0,-0x1a(%rbp,%rax,1)
cmpl   $0x0,-0x24(%rbp)
jne    1266 <get_addr+0x116>
jmp    1173 <get_addr+0x23>
cmpl   $0x0,-0x20(%rbp)
jne    127d <get_addr+0x12d>
movq   $0x0,-0x8(%rbp)
jmp    12c8 <get_addr+0x178>
movl   $0x1,-0x24(%rbp)
lea    -0x1a(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1030 <atox@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    12b6 <get_addr+0x166>
lea    -0x1a(%rbp),%rsi
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1070 <c40_printf@plt>
jmp    12c3 <get_addr+0x173>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12c8 <get_addr+0x178>
jmp    1173 <get_addr+0x23>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_addr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movb   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xe92(%rip),%r12
xor    %r14d,%r14d
lea    0x8(%rsp),%r13
jmp    118a <get_addr+0x4a>
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
test   %ebp,%ebp
jne    1271 <get_addr+0x131>
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1060 <c40_printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <c40_printf@plt>
movl   $0x1,0x4(%rsp)
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <c40_getchar@plt>
mov    %eax,%ebp
movsbl %al,%edi
call   1050 <c40_putchar@plt>
cmp    $0xa,%al
je     1220 <get_addr+0xe0>
cmp    $0xd,%bpl
je     11b0 <get_addr+0x70>
cmp    $0x8,%bpl
jne    11e1 <get_addr+0xa1>
sub    $0x1,%r15d
cmovb  %r14d,%r15d
cmp    $0x9,%r15d
jl     11b0 <get_addr+0x70>
jmp    11f3 <get_addr+0xb3>
movslq %r15d,%rax
add    $0x1,%r15d
mov    %bpl,0x8(%rsp,%rax,1)
cmp    $0x9,%r15d
jl     11b0 <get_addr+0x70>
xor    %ebp,%ebp
lea    0xe13(%rip),%rdi
xor    %eax,%eax
call   1060 <c40_printf@plt>
movl   $0x0,0x4(%rsp)
mov    %r15d,%eax
movb   $0x0,0x8(%rsp,%rax,1)
jmp    1182 <get_addr+0x42>
nopl   0x0(%rax,%rax,1)
movslq %r15d,%rax
movb   $0x0,0x8(%rsp,%rax,1)
cmpl   $0x0,0x4(%rsp)
je     1180 <get_addr+0x40>
test   %r15d,%r15d
je     1271 <get_addr+0x131>
movl   $0x1,0x4(%rsp)
mov    %r13,%rdi
lea    0x4(%rsp),%rsi
call   1030 <atox@plt>
cmpl   $0x0,0x4(%rsp)
jne    126e <get_addr+0x12e>
lea    0xdc5(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <c40_printf@plt>
mov    0x4(%rsp),%ebp
jmp    1182 <get_addr+0x42>
mov    %rax,%r14
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [15 x i8] c"%s Address => \00"
@.str.2 = [17 x i8] c"\0ALine too long.\0A\00"
@.str.3 = [25 x i8] c"Not a valid number : %s\0A\00"
define i64 @get_addr(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8
%5 = alloca [9 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %3
%9 = bitcast [9 x i8]* %5 to i8*
store i32 0, i32* %7
br label %10
10: ; preds = %73, %58, %1
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %74
14: ; preds = %10
%15 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 1, i32* %7
store i32 0, i32* %6
br label %18
18: ; preds = %51, %38, %14
%19 = call signext i8 (...) @c40_getchar()
store i8 %19, i8* %4
%20 = call signext i8 @c40_putchar(i8 signext %19)
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %52
23: ; preds = %18
%24 = load i8, i8* %4
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 8
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %6
%32 = add nsw i32 %31, -1
store i32 %32, i32* %6
br label %33
33: ; preds = %30, %27
br label %46
34: ; preds = %23
%35 = load i8, i8* %4
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 13
br i1 %37, label %38, label %39
38: ; preds = %34
br label %18
39: ; preds = %34
%40 = load i8, i8* %4
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 %43
store i8 %40, i8* %44
br label %45
45: ; preds = %39
br label %46
46: ; preds = %45, %33
%47 = load i32, i32* %6
%48 = icmp sgt i32 %47, 8
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %7
br label %52
51: ; preds = %46
br label %18
52: ; preds = %49, %18
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 %54
store i8 0, i8* %55
%56 = load i32, i32* %7
%57 = icmp ne i32 %56, 0
br i1 %57, label %59, label %58
58: ; preds = %52
br label %10
59: ; preds = %52
%60 = load i32, i32* %6
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59
store i64 0, i64* %2
br label %74
63: ; preds = %59
store i32 1, i32* %7
%64 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%65 = call i64 @atox(i8* %64, i32* %7)
store i64 %65, i64* %8
%66 = load i32, i32* %7
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%70 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %69)
br label %73
71: ; preds = %63
%72 = load i64, i64* %8
store i64 %72, i64* %2
br label %74
73: ; preds = %68
br label %10
74: ; preds = %62, %71, %10
%75 = load i64, i64* %2
ret i64 %75
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [15 x i8] c"%s Address => \00"
@.str.2 = [17 x i8] c"\0ALine too long.\0A\00"
@.str.3 = [25 x i8] c"Not a valid number : %s\0A\00"
define i64 @get_addr(i8* %0) {
%2 = alloca [9 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
br label %6
6: ; preds = %1, %45
%7 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
store i32 1, i32* %3
br label %9
9: ; preds = %24, %6
%10 = phi i32 [ %25, %24 ], [ 0, %6 ]
br label %11
11: ; preds = %9, %15
%12 = call signext i8 (...) @c40_getchar()
%13 = call signext i8 @c40_putchar(i8 signext %12)
%14 = icmp eq i8 %13, 10
br i1 %14, label %31, label %15
15: ; preds = %11
switch i8 %12, label %20 [
i8 8, label %16
i8 13, label %11
]
16: ; preds = %15
%17 = icmp eq i32 %10, 0
%18 = add nsw i32 %10, -1
%19 = select i1 %17, i32 0, i32 %18
br label %24
20: ; preds = %15
%21 = add nsw i32 %10, 1
%22 = sext i32 %10 to i64
%23 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 %22
store i8 %12, i8* %23
br label %24
24: ; preds = %16, %20
%25 = phi i32 [ %21, %20 ], [ %19, %16 ]
%26 = icmp sgt i32 %25, 8
br i1 %26, label %27, label %9
27: ; preds = %24
%28 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
%29 = zext i32 %25 to i64
%30 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 %29
store i8 0, i8* %30
br label %45
31: ; preds = %11
%32 = load i32, i32* %3
%33 = sext i32 %10 to i64
%34 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 %33
store i8 0, i8* %34
%35 = icmp eq i32 %32, 0
br i1 %35, label %45, label %36
36: ; preds = %31
%37 = icmp eq i32 %10, 0
br i1 %37, label %48, label %38
38: ; preds = %36
store i32 1, i32* %3
%39 = call i64 @atox(i8* %4, i32* %3)
%40 = load i32, i32* %3
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = call i32 (i8*, ...) @c40_printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%44 = load i32, i32* %3
br label %45
45: ; preds = %27, %42, %31
%46 = phi i32 [ 0, %31 ], [ %44, %42 ], [ 0, %27 ]
%47 = icmp eq i32 %46, 0
br i1 %47, label %6, label %48
48: ; preds = %45, %38, %36
%49 = phi i64 [ 0, %36 ], [ %39, %38 ], [ undef, %45 ]
ret i64 %49
}