#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 *, char *, unsigned int *);
int GdbmiString2Num(char *s, unsigned *Num) {
  int Result = -1;
  if (1 == sscanf(s, "0X%x", Num))
    Result = 0;
  else if (1 == sscanf(s, "0%o", Num))
    Result = 0;
  else if (1 == sscanf(s, "%d", Num))
    Result = 0;
  return Result;
}


x86 assembly (clang, -O0):
<GdbmiString2Num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeca(%rip),%rsi
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    1156 <GdbmiString2Num+0x46>
movl   $0x0,-0x14(%rbp)
jmp    11b9 <GdbmiString2Num+0xa9>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xea0(%rip),%rsi
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    1185 <GdbmiString2Num+0x75>
movl   $0x0,-0x14(%rbp)
jmp    11b4 <GdbmiString2Num+0xa4>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe75(%rip),%rsi
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    11af <GdbmiString2Num+0x9f>
movl   $0x0,-0x14(%rbp)
jmp    11b4 <GdbmiString2Num+0xa4>
jmp    11b9 <GdbmiString2Num+0xa9>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GdbmiString2Num>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xedf(%rip),%rsi
mov    %r14,%rdx
call   1030 <sscanf@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
je     1164 <GdbmiString2Num+0x54>
lea    0xece(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1164 <GdbmiString2Num+0x54>
lea    0xebb(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <sscanf@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
setne  %bpl
neg    %ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0X%x\00"
@.str.1 = [4 x i8] c"0%o\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @GdbmiString2Num(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 -1, i32* %5
%6 = load i8*, i8** %3
%7 = load i32*, i32** %4
%8 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %7)
%9 = icmp eq i32 1, %8
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %5
br label %25
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i32*, i32** %4
%14 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %13)
%15 = icmp eq i32 1, %14
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 0, i32* %5
br label %24
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = load i32*, i32** %4
%20 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %19)
%21 = icmp eq i32 1, %20
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 0, i32* %5
br label %23
23: ; preds = %22, %17
br label %24
24: ; preds = %23, %16
br label %25
25: ; preds = %24, %10
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@.str = [5 x i8] c"0X%x\00"
@.str.1 = [4 x i8] c"0%o\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @GdbmiString2Num(i8* nocapture %0, i32* %1) {
%3 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%10 = icmp ne i32 %9, 1
%11 = sext i1 %10 to i32
br label %12
12: ; preds = %8, %5, %2
%13 = phi i32 [ 0, %2 ], [ 0, %5 ], [ %11, %8 ]
ret i32 %13
}