#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 int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
uint32_t parse_integer(char *buffer) {
  int base = 10;
  for (;; buffer++) {
    switch (*buffer) {
    case '$':
      base = 16;
      break;
    case 0:
    case '\n':
      return 0;
    case ' ':
      break;
    default:
      return strtol(buffer, NULL, base);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xa,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x24,%eax
ja     116a <parse_integer+0x5a>
mov    -0x20(%rbp),%rax
lea    0xebc(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x10,-0x14(%rbp)
jmp    1182 <parse_integer+0x72>
movl   $0x0,-0x4(%rbp)
jmp    1198 <parse_integer+0x88>
jmp    1182 <parse_integer+0x72>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtol@plt>
mov    %eax,-0x4(%rbp)
jmp    1198 <parse_integer+0x88>
jmp    1187 <parse_integer+0x77>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1123 <parse_integer+0x13>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_integer>:
mov    $0xa,%edx
lea    0xee4(%rip),%rax
jmp    1124 <parse_integer+0x14>
xchg   %ax,%ax
add    $0x1,%rdi
movsbl (%rdi),%ecx
cmp    $0x24,%ecx
ja     113f <parse_integer+0x2f>
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    $0x10,%edx
jmp    1120 <parse_integer+0x10>
xor    %eax,%eax
ret
xor    %esi,%esi
jmp    1030 <strtol@plt>

LLVM IR (-O0):
define i32 @parse_integer(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 10, i32* %4
br label %5
5: ; preds = %17, %1
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %12 [
i32 36, label %9
i32 0, label %10
i32 10, label %10
i32 32, label %11
]
9: ; preds = %5
store i32 16, i32* %4
br label %16
10: ; preds = %5, %5
store i32 0, i32* %2
br label %20
11: ; preds = %5
br label %16
12: ; preds = %5
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = call i32 @strtol(i8* %13, i32* null, i32 %14)
store i32 %15, i32* %2
br label %20
16: ; preds = %11, %9
br label %17
17: ; preds = %16
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
br label %5
20: ; preds = %12, %10
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
define i32 @parse_integer(i8* nocapture %0) {
br label %2
2: ; preds = %10, %1
%3 = phi i8* [ %0, %1 ], [ %12, %10 ]
%4 = phi i32 [ 10, %1 ], [ %11, %10 ]
%5 = load i8, i8* %3
%6 = sext i8 %5 to i32
switch i32 %6, label %8 [
i32 36, label %7
i32 0, label %13
i32 10, label %13
i32 32, label %10
]
7: ; preds = %2
br label %10
8: ; preds = %2
%9 = tail call i32 @strtol(i8* nocapture %3, i32* null, i32 %4)
br label %13
10: ; preds = %7, %2
%11 = phi i32 [ %4, %2 ], [ 16, %7 ]
%12 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
13: ; preds = %2, %2, %8
%14 = phi i32 [ %9, %8 ], [ 0, %2 ], [ 0, %2 ]
ret i32 %14
}