#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 */
typedef scalar_t__ uint32_t;

/* Variables and functions */
scalar_t__ sscanf(char *, char *, int *);
scalar_t__ strcmp(char *, char *);
int read_literal(char *literal, uint32_t *value) {
  if (strcmp(literal, "0") == 0) {
    *value = 0;
    return 0;
  } else if (sscanf(literal, "0x%x", (int *)value) != 0) {
    return 0;
  } else if (sscanf(literal, "0%o", (int *)value) != 0) {
    return 0;
  } else if (sscanf(literal, "%d", (int *)value) != 0) {
    return 0;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<read_literal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec5(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1161 <read_literal+0x41>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11e6 <read_literal+0xc6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe92(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x0,%rax
je     118b <read_literal+0x6b>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <read_literal+0xc6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe6d(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x0,%rax
je     11b5 <read_literal+0x95>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <read_literal+0xc6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe47(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x0,%rax
je     11df <read_literal+0xbf>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <read_literal+0xc6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_literal>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xecf(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1188 <read_literal+0x68>
lea    0xec0(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1191 <read_literal+0x71>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
test   %rax,%rax
jne    1191 <read_literal+0x71>
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
jmp    1191 <read_literal+0x71>
movq   $0x0,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.1 = [5 x i8] c"0x%x\00"
@.str.2 = [4 x i8] c"0%o\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @read_literal(i8* %0, i64* %1) {
%3 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %2
store i64 0, i64* %1
br label %17
6: ; preds = %2
%7 = bitcast i64* %1 to i32*
%8 = tail call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = tail call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = tail call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %13, %10, %6, %5
%18 = phi i32 [ 0, %5 ], [ 0, %6 ], [ 0, %10 ], [ %16, %13 ]
ret i32 %18
}