#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 */
typedef int /*<<< orphan*/ line;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
scalar_t__ hex_to_long(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
void *get_address(void) {
  char line[80];
  void *pnt;
  do {
    (void)printf("Enter a hex address: ");
    if (fgets(line, sizeof(line), stdin) == NULL) {
      return NULL;
    }
  } while (line[0] == '\0');
  pnt = (void *)hex_to_long(line);
  return pnt;
}


x86 assembly (clang, -O0):
<get_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1172 <get_address+0x42>
movq   $0x0,-0x8(%rbp)
jmp    1199 <get_address+0x69>
jmp    1177 <get_address+0x47>
movsbl -0x60(%rbp),%eax
cmp    $0x0,%eax
je     1138 <get_address+0x8>
lea    -0x60(%rbp),%rdi
call   1040 <hex_to_long@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_address>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xebe(%rip),%r15
mov    0x2e9f(%rip),%r12
mov    %rsp,%rbx
xor    %r14d,%r14d
nop
mov    %r15,%rdi
call   1030 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     117f <get_address+0x4f>
cmpb   $0x0,(%rsp)
je     1150 <get_address+0x20>
mov    %rsp,%rdi
call   1040 <hex_to_long@plt>
mov    %rax,%r14
mov    %r14,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter a hex address: \00"
@stdin = global i32 0
define i8* @get_address() {
%1 = alloca i8*
%2 = alloca [80 x i8]
%3 = alloca i8*
br label %4
4: ; preds = %12, %0
%5 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 80, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %4
store i8* null, i8** %1
br label %22
11: ; preds = %4
br label %12
12: ; preds = %11
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %4, label %17
17: ; preds = %12
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%19 = call i64 @hex_to_long(i8* %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %3
%21 = load i8*, i8** %3
store i8* %21, i8** %1
br label %22
22: ; preds = %17, %10
%23 = load i8*, i8** %1
ret i8* %23
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter a hex address: \00"
@stdin = global i32 0
define i8* @get_address() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %8, %0
%4 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32* @fgets(i8* %2, i32 80, i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %3
%9 = load i8, i8* %2
%10 = icmp eq i8 %9, 0
br i1 %10, label %3, label %11
11: ; preds = %8
%12 = call i64 @hex_to_long(i8* %2)
%13 = inttoptr i64 %12 to i8*
br label %14
14: ; preds = %3, %11
%15 = phi i8* [ %13, %11 ], [ null, %3 ]
ret i8* %15
}