#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 hextou(char const *);
int /*<<< orphan*/ rerun(char *);
unsigned dectou(const char *h) {
  if (h[0] == '0' && h[1] == 'x')
    return hextou(h);
  unsigned result = 0;
  do {
    unsigned c = *h - '0';
    if (c >= 10)
      rerun("Illegal decimal\n");
    result = result * 10 + c;
  } while (*++h);
  return result;
}


x86 assembly (clang, -O0):
<dectou>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    115e <dectou+0x3e>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    115e <dectou+0x3e>
mov    -0x10(%rbp),%rdi
call   1040 <hextou@plt>
mov    %eax,-0x4(%rbp)
jmp    11b1 <dectou+0x91>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jb     1188 <dectou+0x68>
lea    0xe7d(%rip),%rdi
call   1030 <rerun@plt>
imul   $0xa,-0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
cmpb   $0x0,0x1(%rax)
jne    1165 <dectou+0x45>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dectou>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    (%rdi),%al
cmp    $0x30,%al
jne    114c <dectou+0x2c>
cmpb   $0x78,0x1(%r12)
jne    114c <dectou+0x2c>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <hextou@plt>
add    $0x1,%r12
xor    %r15d,%r15d
lea    0xea6(%rip),%r14
jmp    1175 <dectou+0x55>
nopl   0x0(%rax)
lea    (%r15,%r15,4),%eax
lea    (%rbx,%rax,2),%r15d
movzbl (%r12),%eax
add    $0x1,%r12
test   %al,%al
je     118a <dectou+0x6a>
movsbl %al,%ebx
add    $0xffffffd0,%ebx
cmp    $0xa,%ebx
jb     1160 <dectou+0x40>
mov    %r14,%rdi
call   1030 <rerun@plt>
jmp    1160 <dectou+0x40>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Illegal decimal\0A\00"
define i32 @dectou(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 48
br i1 %10, label %11, label %20
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 120
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = call i32 @hextou(i8* %18)
store i32 %19, i32* %2
br label %42
20: ; preds = %11, %1
store i32 0, i32* %4
br label %21
21: ; preds = %35, %20
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = sub nsw i32 %24, 48
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp uge i32 %26, 10
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @rerun(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %21
%31 = load i32, i32* %4
%32 = mul i32 %31, 10
%33 = load i32, i32* %5
%34 = add i32 %32, %33
store i32 %34, i32* %4
br label %35
35: ; preds = %30
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %3
%38 = load i8, i8* %37
%39 = icmp ne i8 %38, 0
br i1 %39, label %21, label %40
40: ; preds = %35
%41 = load i32, i32* %4
store i32 %41, i32* %2
br label %42
42: ; preds = %40, %17
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@.str = [17 x i8] c"Illegal decimal\0A\00"
define i32 @dectou(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 48
br i1 %3, label %5, label %4
4: ; preds = %5, %1
br label %11
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 120
br i1 %8, label %9, label %4
9: ; preds = %5
%10 = tail call i32 @hextou(i8* %0)
br label %26
11: ; preds = %4, %20
%12 = phi i8 [ %24, %20 ], [ %2, %4 ]
%13 = phi i8* [ %23, %20 ], [ %0, %4 ]
%14 = phi i32 [ %22, %20 ], [ 0, %4 ]
%15 = sext i8 %12 to i32
%16 = add nsw i32 %15, -48
%17 = icmp ugt i32 %16, 9
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = tail call i32 @rerun(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %11
%21 = mul i32 %14, 10
%22 = add i32 %16, %21
%23 = getelementptr inbounds i8, i8* %13, i64 1
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %11
26: ; preds = %20, %9
%27 = phi i32 [ %10, %9 ], [ %22, %20 ]
ret i32 %27
}