#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 atoi(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ sscanf(char *, char *, int *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int number_arg(char *str) {
  char *hex_prefix = "0x";
  char prfx[3] = "\0\0\0";
  int value = -1;
  if (strlen(str) > 63) {
    printf("ERROR: option too long\n");
    return -1;
  }
  if (strlen(str) > 2) {
    strncpy(prfx, str, 2);
    if (strcmp(hex_prefix, prfx) == 0) {
      if (sscanf(str, "0x%x", &value) == 0)
        value = -1;
      return value;
    }
  }
  value = atoi(str);
  return value;
}


x86 assembly (clang, -O0):
<number_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x1b(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1060 <memset@plt>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x3f,%eax
jle    11c8 <number_arg+0x58>
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <number_arg+0xda>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jle    1238 <number_arg+0xc8>
lea    -0x1b(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1233 <number_arg+0xc3>
mov    -0x10(%rbp),%rdi
lea    0xe0d(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x0,%rax
jne    1228 <number_arg+0xb8>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124a <number_arg+0xda>
jmp    1238 <number_arg+0xc8>
mov    -0x10(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<number_arg>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movb   $0x0,0x2(%rsp)
movw   $0x0,(%rsp)
movl   $0xffffffff,0x4(%rsp)
ff
call   1050 <strlen@plt>
cmp    $0x40,%eax
jl     1197 <number_arg+0x37>
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    11f3 <number_arg+0x93>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x3,%eax
jl     11cb <number_arg+0x6b>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
lea    0xe42(%rip),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11d5 <number_arg+0x75>
mov    %rbx,%rdi
call   1080 <atoi@plt>
jmp    11f3 <number_arg+0x93>
lea    0xe27(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <sscanf@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
or     0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
@.str.1 = [24 x i8] c"ERROR: option too long\0A\00"
@.str.2 = [5 x i8] c"0x%x\00"
define i32 @number_arg(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [3 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4
%7 = bitcast [3 x i8]* %5 to i8*
store i32 -1, i32* %6
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp sgt i32 %9, 63
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %37
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = icmp sgt i32 %15, 2
br i1 %16, label %17, label %33
17: ; preds = %13
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = call i32 @strncpy(i8* %18, i8* %19, i32 2)
%21 = load i8*, i8** %4
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%23 = call i64 @strcmp(i8* %21, i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %17
%26 = load i8*, i8** %3
%27 = call i64 @sscanf(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 -1, i32* %6
br label %30
30: ; preds = %29, %25
%31 = load i32, i32* %6
store i32 %31, i32* %2
br label %37
32: ; preds = %17
br label %33
33: ; preds = %32, %13
%34 = load i8*, i8** %3
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %6
%36 = load i32, i32* %6
store i32 %36, i32* %2
br label %37
37: ; preds = %33, %30, %11
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
@.str.2 = [5 x i8] c"0x%x\00"
@str = [23 x i8] c"ERROR: option too long\00"
define i32 @number_arg(i8* %0) {
%2 = alloca [3 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 63
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %24
10: ; preds = %1
%11 = tail call i32 @strlen(i8* %0)
%12 = icmp sgt i32 %11, 2
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = call i32 @strncpy(i8* %4, i8* %0, i32 2)
%15 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%19 = icmp eq i64 %18, 0
%20 = load i32, i32* %3
%21 = select i1 %19, i32 -1, i32 %20
br label %24
22: ; preds = %13, %10
%23 = call i32 @atoi(i8* %0)
br label %24
24: ; preds = %17, %22, %8
%25 = phi i32 [ -1, %8 ], [ %23, %22 ], [ %21, %17 ]
ret i32 %25
}