#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 */
long strtol(char *, char **, int);
int read_long(long *z, char *str) {
  char *end;
  int radix = 10;
  if (*str == '#') {
    ++str;
    switch (*str) {
    case 'x':
    case 'X':
      radix = 16;
      break;
    case 'd':
    case 'D':
      radix = 10;
      break;
    case 'o':
    case 'O':
      radix = 8;
      break;
    case 'b':
    case 'B':
      radix = 2;
      break;
    default:
      return 0;
    }
    ++str;
  }
  *z = strtol(str, &end, radix);
  return (end != str && *end == '\0');
}


x86 assembly (clang, -O0):
<read_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xa,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11b8 <read_long+0xa8>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffbe,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x36,%eax
ja     11a0 <read_long+0x90>
mov    -0x30(%rbp),%rax
lea    0xe99(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x10,-0x24(%rbp)
jmp    11ac <read_long+0x9c>
movl   $0xa,-0x24(%rbp)
jmp    11ac <read_long+0x9c>
movl   $0x8,-0x24(%rbp)
jmp    11ac <read_long+0x9c>
movl   $0x2,-0x24(%rbp)
jmp    11ac <read_long+0x9c>
movl   $0x0,-0x4(%rbp)
jmp    1200 <read_long+0xf0>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x31(%rbp)
je     11f5 <read_long+0xe5>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_long>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0xa,%edx
cmpb   $0x23,(%rsi)
jne    115e <read_long+0x4e>
movsbl 0x1(%rbx),%ecx
xor    %eax,%eax
add    $0xffffffbe,%ecx
cmp    $0x36,%ecx
ja     117d <read_long+0x6d>
mov    $0x10,%edx
lea    0xec2(%rip),%rsi
movslq (%rsi,%rcx,4),%rcx
add    %rsi,%rcx
jmp    *%rcx
mov    $0x2,%edx
jmp    115a <read_long+0x4a>
mov    $0xa,%edx
jmp    115a <read_long+0x4a>
mov    $0x8,%edx
add    $0x2,%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strtol@plt>
mov    %rax,(%r14)
mov    (%rsp),%rcx
xor    %eax,%eax
cmp    %rbx,%rcx
je     117d <read_long+0x6d>
cmpb   $0x0,(%rcx)
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @read_long(i64* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i64* %0, i64** %4
store i8* %1, i8** %5
store i32 10, i32* %7
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 35
br i1 %11, label %12, label %26
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %22 [
i32 120, label %18
i32 88, label %18
i32 100, label %19
i32 68, label %19
i32 111, label %20
i32 79, label %20
i32 98, label %21
i32 66, label %21
]
18: ; preds = %12, %12
store i32 16, i32* %7
br label %23
19: ; preds = %12, %12
store i32 10, i32* %7
br label %23
20: ; preds = %12, %12
store i32 8, i32* %7
br label %23
21: ; preds = %12, %12
store i32 2, i32* %7
br label %23
22: ; preds = %12
store i32 0, i32* %3
br label %42
23: ; preds = %21, %20, %19, %18
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %5
br label %26
26: ; preds = %23, %2
%27 = load i8*, i8** %5
%28 = load i32, i32* %7
%29 = call i64 @strtol(i8* %27, i8** %6, i32 %28)
%30 = load i64*, i64** %4
store i64 %29, i64* %30
%31 = load i8*, i8** %6
%32 = load i8*, i8** %5
%33 = icmp ne i8* %31, %32
br i1 %33, label %34, label %39
34: ; preds = %26
%35 = load i8*, i8** %6
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br label %39
39: ; preds = %34, %26
%40 = phi i1 [ false, %26 ], [ %38, %34 ]
%41 = zext i1 %40 to i32
store i32 %41, i32* %3
br label %42
42: ; preds = %39, %22
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
define i32 @read_long(i64* nocapture writeonly %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 35
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %1, i64 1
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
switch i32 %10, label %27 [
i32 120, label %14
i32 88, label %14
i32 100, label %11
i32 68, label %11
i32 111, label %12
i32 79, label %12
i32 98, label %13
i32 66, label %13
]
11: ; preds = %7, %7
br label %14
12: ; preds = %7, %7
br label %14
13: ; preds = %7, %7
br label %14
14: ; preds = %7, %7, %13, %12, %11
%15 = phi i32 [ 2, %13 ], [ 8, %12 ], [ 10, %11 ], [ 16, %7 ], [ 16, %7 ]
%16 = getelementptr inbounds i8, i8* %1, i64 2
br label %17
17: ; preds = %14, %2
%18 = phi i8* [ %16, %14 ], [ %1, %2 ]
%19 = phi i32 [ %15, %14 ], [ 10, %2 ]
%20 = call i64 @strtol(i8* %18, i8** %3, i32 %19)
store i64 %20, i64* %0
%21 = load i8*, i8** %3
%22 = icmp eq i8* %21, %18
br i1 %22, label %27, label %23
23: ; preds = %17
%24 = load i8, i8* %21
%25 = icmp eq i8 %24, 0
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %17, %23, %7
%28 = phi i32 [ 0, %7 ], [ 0, %17 ], [ %26, %23 ]
ret i32 %28
}