#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 sscanf(char const *, char *, unsigned long *);
int /*<<< orphan*/ usage(char const *, char const *, char *);
unsigned long read_address(const char *option, int argc, const char *argv[],
                           int i) {
  unsigned long address;
  if (i >= argc) {
    usage(*argv, option, "Value for the option missing");
  }
  if (sscanf(argv[i], "0x%lx", &address) != 1) {
    usage(*argv, option, "Failed reading the hex value");
  }
  return address;
}


x86 assembly (clang, -O0):
<read_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     1159 <read_address+0x39>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
lea    0xeac(%rip),%rdx
call   1040 <usage@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xeb1(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1195 <read_address+0x75>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
lea    0xe93(%rip),%rdx
call   1040 <usage@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_address>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %rdi,%r14
cmp    %esi,%ecx
jl     1146 <read_address+0x26>
mov    (%rbx),%rdi
lea    0xec2(%rip),%rdx
mov    %r14,%rsi
call   1040 <usage@plt>
movslq %ebp,%rax
mov    (%rbx,%rax,8),%rdi
lea    0xec9(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1175 <read_address+0x55>
mov    (%rbx),%rdi
lea    0xeb6(%rip),%rdx
mov    %r14,%rsi
call   1040 <usage@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Value for the option missing\00"
@.str.1 = [6 x i8] c"0x%lx\00"
@.str.2 = [29 x i8] c"Failed reading the hex value\00"
define i64 @read_address(i8* %0, i32 %1, i8** %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i32 %3, i32* %8
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp sge i32 %10, %11
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = load i8**, i8*** %7
%15 = load i8*, i8** %14
%16 = load i8*, i8** %5
%17 = call i32 @usage(i8* %15, i8* %16, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %13, %4
%19 = load i8**, i8*** %7
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64* %9)
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %31
26: ; preds = %18
%27 = load i8**, i8*** %7
%28 = load i8*, i8** %27
%29 = load i8*, i8** %5
%30 = call i32 @usage(i8* %28, i8* %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %26, %18
%32 = load i64, i64* %9
ret i64 %32
}

LLVM IR (-O2):
@.str = [29 x i8] c"Value for the option missing\00"
@.str.1 = [6 x i8] c"0x%lx\00"
@.str.2 = [29 x i8] c"Failed reading the hex value\00"
define i64 @read_address(i8* %0, i32 %1, i8** nocapture %2, i32 %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = icmp slt i32 %3, %1
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = load i8*, i8** %2
%10 = tail call i32 @usage(i8* %9, i8* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %4
%12 = sext i32 %3 to i64
%13 = getelementptr inbounds i8*, i8** %2, i64 %12
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64* %5)
%16 = icmp eq i32 %15, 1
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = load i8*, i8** %2
%19 = call i32 @usage(i8* %18, i8* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %17, %11
%21 = load i64, i64* %5
ret i64 %21
}