#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ sscanf(char const *, char *, int *);
int /*<<< orphan*/ stderr;
int read_int_dec_or_hex(const char *str) {
  int ret;
  if (sscanf(str, "0x%x", &ret) > 0)
    return ret;
  if (sscanf(str, "%d", &ret) > 0)
    return ret;
  fprintf(stderr,
          "ERROR: "
          "Unable to parse value %s\n",
          str);
  return 0;
}


x86 assembly (clang, -O0):
<read_int_dec_or_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec9(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x0,%rax
jle    1155 <read_int_dec_or_hex+0x35>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119e <read_int_dec_or_hex+0x7e>
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x0,%rax
jle    117e <read_int_dec_or_hex+0x5e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119e <read_int_dec_or_hex+0x7e>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int_dec_or_hex>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xed1(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1040 <sscanf@plt>
test   %rax,%rax
jg     1157 <read_int_dec_or_hex+0x37>
lea    0xec0(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
test   %rax,%rax
jle    1161 <read_int_dec_or_hex+0x41>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
xor    %eax,%eax
jmp    115b <read_int_dec_or_hex+0x3b>

LLVM IR (-O0):
@.str = [5 x i8] c"0x%x\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"ERROR: Unable to parse value %s\0A\00"
define i32 @read_int_dec_or_hex(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @sscanf(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %4)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i32, i32* %4
store i32 %9, i32* %2
br label %20
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i64 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = load i32, i32* %4
store i32 %15, i32* %2
br label %20
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %3
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %18)
store i32 0, i32* %2
br label %20
20: ; preds = %16, %14, %8
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str = [5 x i8] c"0x%x\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [33 x i8] c"ERROR: Unable to parse value %s\0A\00"
define i32 @read_int_dec_or_hex(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = load i32, i32* %2
br label %16
8: ; preds = %1
%9 = call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = load i32, i32* %2
br label %16
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %13, %11, %6
%17 = phi i32 [ %7, %6 ], [ %12, %11 ], [ 0, %13 ]
ret i32 %17
}