#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 /*<<< orphan*/ e_strtoul(int, char const *, unsigned long, int);
unsigned long strtoul(char const *, char **, int);
void test_string_strtoul(const char *s, unsigned long value, int base) {
  char *end;
  unsigned long result;
  result = strtoul(s, &end, base);
  if (result != value)
    e_strtoul(1, s, result, base);
  if (*end)
    e_strtoul(2, s, result, base);
}


x86 assembly (clang, -O0):
<test_string_strtoul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rsi
call   1040 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     116a <test_string_strtoul+0x4a>
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x1,%edi
call   1030 <e_strtoul@plt>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     118c <test_string_strtoul+0x6c>
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x2,%edi
call   1030 <e_strtoul@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_string_strtoul>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1040 <strtoul@plt>
mov    %rax,%rbp
cmp    %r15,%rax
je     1153 <test_string_strtoul+0x33>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
call   1030 <e_strtoul@plt>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     1179 <test_string_strtoul+0x59>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <e_strtoul@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @test_string_strtoul(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = load i32, i32* %6
%11 = call i64 @strtoul(i8* %9, i8** %7, i32 %10)
store i64 %11, i64* %8
%12 = load i64, i64* %8
%13 = load i64, i64* %5
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = load i64, i64* %8
%18 = load i32, i32* %6
%19 = call i32 @e_strtoul(i32 1, i8* %16, i64 %17, i32 %18)
br label %20
20: ; preds = %15, %3
%21 = load i8*, i8** %7
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i64, i64* %8
%27 = load i32, i32* %6
%28 = call i32 @e_strtoul(i32 2, i8* %25, i64 %26, i32 %27)
br label %29
29: ; preds = %24, %20
ret void
}

LLVM IR (-O2):
define void @test_string_strtoul(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i64 @strtoul(i8* %0, i8** %4, i32 %2)
%7 = icmp eq i64 %6, %1
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @e_strtoul(i32 1, i8* %0, i64 %6, i32 %2)
br label %10
10: ; preds = %8, %3
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @e_strtoul(i32 2, i8* %0, i64 %6, i32 %2)
br label %16
16: ; preds = %14, %10
ret void
}