#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 */
scalar_t__ lib_memcmp(char const *, char *, int);
int lib_strlen(char const *);
scalar_t__ lib_xtoi(char const *);
scalar_t__ lib_xtoq(char const *);
int getaddrarg(const char *x, long *addr) {
  int res;
  res = 0;
  *addr = 0;
  if (x) {
    int longaddr;
    longaddr = lib_strlen(x);
    if (lib_memcmp(x, "0x", 2) == 0)
      longaddr -= 2;
    *addr = (longaddr > 8) ? (long)lib_xtoq(x) : (long)lib_xtoi(x);
    res = 1;
  }
  return res;
}


x86 assembly (clang, -O0):
<getaddrarg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x8(%rbp)
je     11dc <getaddrarg+0x9c>
mov    -0x8(%rbp),%rdi
call   1060 <lib_strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x2,%edx
call   1040 <lib_memcmp@plt>
cmp    $0x0,%rax
jne    11a1 <getaddrarg+0x61>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jle    11bd <getaddrarg+0x7d>
mov    -0x8(%rbp),%rdi
call   1030 <lib_xtoq@plt>
mov    %rax,-0x20(%rbp)
jmp    11ca <getaddrarg+0x8a>
mov    -0x8(%rbp),%rdi
call   1050 <lib_xtoi@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getaddrarg>:
push   %r15
push   %r14
push   %rbx
movq   $0x0,(%rsi)
test   %rdi,%rdi
je     118d <getaddrarg+0x4d>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <lib_strlen@plt>
mov    %eax,%r15d
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1040 <lib_memcmp@plt>
lea    -0x2(%r15),%ecx
test   %rax,%rax
cmovne %r15d,%ecx
mov    %rbx,%rdi
cmp    $0x9,%ecx
jl     1191 <getaddrarg+0x51>
call   1030 <lib_xtoq@plt>
jmp    1196 <getaddrarg+0x56>
xor    %eax,%eax
jmp    119e <getaddrarg+0x5e>
call   1050 <lib_xtoi@plt>
mov    %rax,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
define i32 @getaddrarg(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i64* %1, i64** %4
store i32 0, i32* %5
%7 = load i64*, i64** %4
store i64 0, i64* %7
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %31
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @lib_strlen(i8* %11)
store i32 %12, i32* %6
%13 = load i8*, i8** %3
%14 = call i64 @lib_memcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* %6
%18 = sub nsw i32 %17, 2
store i32 %18, i32* %6
br label %19
19: ; preds = %16, %10
%20 = load i32, i32* %6
%21 = icmp sgt i32 %20, 8
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = call i64 @lib_xtoq(i8* %23)
br label %28
25: ; preds = %19
%26 = load i8*, i8** %3
%27 = call i64 @lib_xtoi(i8* %26)
br label %28
28: ; preds = %25, %22
%29 = phi i64 [ %24, %22 ], [ %27, %25 ]
%30 = load i64*, i64** %4
store i64 %29, i64* %30
store i32 1, i32* %5
br label %31
31: ; preds = %28, %2
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
define i32 @getaddrarg(i8* %0, i64* nocapture writeonly %1) {
store i64 0, i64* %1
%3 = icmp eq i8* %0, null
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = tail call i32 @lib_strlen(i8* %0)
%6 = tail call i64 @lib_memcmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%7 = icmp eq i64 %6, 0
%8 = add nsw i32 %5, -2
%9 = select i1 %7, i32 %8, i32 %5
%10 = icmp sgt i32 %9, 8
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i64 @lib_xtoq(i8* %0)
br label %15
13: ; preds = %4
%14 = tail call i64 @lib_xtoi(i8* %0)
br label %15
15: ; preds = %13, %11
%16 = phi i64 [ %12, %11 ], [ %14, %13 ]
store i64 %16, i64* %1
br label %17
17: ; preds = %15, %2
%18 = phi i32 [ 1, %15 ], [ 0, %2 ]
ret i32 %18
}