#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 */
unsigned long atol(char *);
unsigned long hex_decimal(char *);
unsigned long oct_decimal(char *);
long read_val(char *inVal) {
  unsigned long retVal;
  if (inVal[0] == '0') {
    if ((inVal[1] == 'X') || (inVal[1] == 'x')) {
      retVal = hex_decimal(inVal);
    } else {
      retVal = oct_decimal(inVal);
    }
  } else {
    retVal = atol(inVal);
  }
  return retVal;
}


x86 assembly (clang, -O0):
<read_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1192 <read_val+0x62>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
je     116e <read_val+0x3e>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    1180 <read_val+0x50>
mov    -0x8(%rbp),%rdi
call   1030 <hex_decimal@plt>
mov    %rax,-0x10(%rbp)
jmp    118d <read_val+0x5d>
mov    -0x8(%rbp),%rdi
call   1040 <oct_decimal@plt>
mov    %rax,-0x10(%rbp)
jmp    119f <read_val+0x6f>
mov    -0x8(%rbp),%rdi
call   1050 <atol@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_val>:
cmpb   $0x30,(%rdi)
jne    1143 <read_val+0x13>
mov    0x1(%rdi),%al
or     $0x20,%al
cmp    $0x78,%al
jne    1148 <read_val+0x18>
jmp    1030 <hex_decimal@plt>
jmp    1050 <atol@plt>
jmp    1040 <oct_decimal@plt>

LLVM IR (-O0):
define i64 @read_val(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 48
br i1 %8, label %9, label %28
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 88
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 120
br i1 %20, label %21, label %24
21: ; preds = %15, %9
%22 = load i8*, i8** %2
%23 = call i64 @hex_decimal(i8* %22)
store i64 %23, i64* %3
br label %27
24: ; preds = %15
%25 = load i8*, i8** %2
%26 = call i64 @oct_decimal(i8* %25)
store i64 %26, i64* %3
br label %27
27: ; preds = %24, %21
br label %31
28: ; preds = %1
%29 = load i8*, i8** %2
%30 = call i64 @atol(i8* %29)
store i64 %30, i64* %3
br label %31
31: ; preds = %28, %27
%32 = load i64, i64* %3
ret i64 %32
}

LLVM IR (-O2):
define i64 @read_val(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 48
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
switch i8 %6, label %9 [
i8 88, label %7
i8 120, label %7
]
7: ; preds = %4, %4
%8 = tail call i64 @hex_decimal(i8* %0)
br label %13
9: ; preds = %4
%10 = tail call i64 @oct_decimal(i8* %0)
br label %13
11: ; preds = %1
%12 = tail call i64 @atol(i8* %0)
br label %13
13: ; preds = %7, %9, %11
%14 = phi i64 [ %8, %7 ], [ %10, %9 ], [ %12, %11 ]
ret i64 %14
}