#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*/ EINVAL;
int /*<<< orphan*/ ERANGE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ mx_strtoul(char *, unsigned long *);
void test_mx_strtoul(void) {
  unsigned long int l;
  assert(mx_strtoul("123", &l) == 0);
  assert(l == 123);
  assert(mx_strtoul("  123  ", &l) == 0);
  assert(l == 123);
  assert(mx_strtoul("0173", &l) == 0);
  assert(l == 123);
  assert(mx_strtoul("0x007b", &l) == 0);
  assert(l == 123);
  assert(mx_strtoul("0x007B", &l) == 0);
  assert(l == 123);
  assert(mx_strtoul("+123", &l) == 0);
  assert(l == 123);
  assert(mx_strtoul("-1", &l) == -ERANGE);
  assert(mx_strtoul(" -1", &l) == -ERANGE);
  assert(mx_strtoul("123 123", &l) == -EINVAL);
  assert(mx_strtoul("123s", &l) == -EINVAL);
  assert(mx_strtoul("0888", &l) == -EINVAL);
  assert(mx_strtoul("1.2", &l) == -EINVAL);
  assert(mx_strtoul("1,2", &l) == -EINVAL);
  assert(mx_strtoul("test", &l) == -EINVAL);
}


x86 assembly (clang, -O0):
<test_mx_strtoul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xef9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x7b,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe9f(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x7b,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe75(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x7b,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe48(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x7b,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe1d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x7b,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xdf2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x7b,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xdc6(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
xor    %ecx,%ecx
mov    0x2d7b(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xd9b(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
xor    %ecx,%ecx
mov    0x2d51(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xd75(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
xor    %ecx,%ecx
mov    0x2d17(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xd53(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
xor    %ecx,%ecx
mov    0x2ced(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xd2e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
xor    %ecx,%ecx
mov    0x2cc3(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xd09(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
xor    %ecx,%ecx
mov    0x2c99(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xce3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
xor    %ecx,%ecx
mov    0x2c6f(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xcbd(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <mx_strtoul@plt>
xor    %ecx,%ecx
mov    0x2c45(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_mx_strtoul>:
push   %r14
push   %rbx
push   %rax
lea    0xefd(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpq   $0x7b,(%rsp)
sete   %dil
call   1040 <assert@plt>
lea    0xea6(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpq   $0x7b,(%rsp)
sete   %dil
call   1040 <assert@plt>
lea    0xe82(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpq   $0x7b,(%rsp)
sete   %dil
call   1040 <assert@plt>
lea    0xe5b(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpq   $0x7b,(%rsp)
sete   %dil
call   1040 <assert@plt>
lea    0xe36(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpq   $0x7b,(%rsp)
sete   %dil
call   1040 <assert@plt>
lea    0xe11(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpq   $0x7b,(%rsp)
sete   %dil
call   1040 <assert@plt>
lea    0xdeb(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
mov    0x2da3(%rip),%rbx
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1040 <assert@plt>
lea    0xdc7(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1040 <assert@plt>
lea    0xdaf(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
mov    0x2d54(%rip),%rbx
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1040 <assert@plt>
lea    0xd94(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1040 <assert@plt>
lea    0xd7d(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1040 <assert@plt>
lea    0xd66(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1040 <assert@plt>
lea    0xd4e(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1040 <assert@plt>
lea    0xd36(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoul@plt>
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1040 <assert@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"123\00"
@.str.1 = [8 x i8] c" 123 \00"
@.str.2 = [5 x i8] c"0173\00"
@.str.3 = [7 x i8] c"0x007b\00"
@.str.4 = [7 x i8] c"0x007B\00"
@.str.5 = [5 x i8] c"+123\00"
@.str.6 = [3 x i8] c"-1\00"
@ERANGE = global i32 0
@.str.7 = [4 x i8] c" -1\00"
@.str.8 = [8 x i8] c"123 123\00"
@EINVAL = global i32 0
@.str.9 = [5 x i8] c"123s\00"
@.str.10 = [5 x i8] c"0888\00"
@.str.11 = [4 x i8] c"1.2\00"
@.str.12 = [4 x i8] c"1,2\00"
@.str.13 = [5 x i8] c"test\00"
define void @test_mx_strtoul() {
%1 = alloca i64
%2 = call i32 @mx_strtoul(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%3 = icmp eq i32 %2, 0
%4 = zext i1 %3 to i32
%5 = call i32 @assert(i32 %4)
%6 = load i64, i64* %1
%7 = icmp eq i64 %6, 123
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = call i32 @mx_strtoul(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i64, i64* %1
%15 = icmp eq i64 %14, 123
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = call i32 @mx_strtoul(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i64, i64* %1
%23 = icmp eq i64 %22, 123
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = call i32 @mx_strtoul(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64* %1)
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i64, i64* %1
%31 = icmp eq i64 %30, 123
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = call i32 @mx_strtoul(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i64* %1)
%35 = icmp eq i32 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i64, i64* %1
%39 = icmp eq i64 %38, 123
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = call i32 @mx_strtoul(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64* %1)
%43 = icmp eq i32 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i64, i64* %1
%47 = icmp eq i64 %46, 123
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = call i32 @mx_strtoul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64* %1)
%51 = load i32, i32* @ERANGE
%52 = sub nsw i32 0, %51
%53 = icmp eq i32 %50, %52
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = call i32 @mx_strtoul(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i64* %1)
%57 = load i32, i32* @ERANGE
%58 = sub nsw i32 0, %57
%59 = icmp eq i32 %56, %58
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = call i32 @mx_strtoul(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i64* %1)
%63 = load i32, i32* @EINVAL
%64 = sub nsw i32 0, %63
%65 = icmp eq i32 %62, %64
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = call i32 @mx_strtoul(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i64* %1)
%69 = load i32, i32* @EINVAL
%70 = sub nsw i32 0, %69
%71 = icmp eq i32 %68, %70
%72 = zext i1 %71 to i32
%73 = call i32 @assert(i32 %72)
%74 = call i32 @mx_strtoul(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i64* %1)
%75 = load i32, i32* @EINVAL
%76 = sub nsw i32 0, %75
%77 = icmp eq i32 %74, %76
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = call i32 @mx_strtoul(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i64* %1)
%81 = load i32, i32* @EINVAL
%82 = sub nsw i32 0, %81
%83 = icmp eq i32 %80, %82
%84 = zext i1 %83 to i32
%85 = call i32 @assert(i32 %84)
%86 = call i32 @mx_strtoul(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i64* %1)
%87 = load i32, i32* @EINVAL
%88 = sub nsw i32 0, %87
%89 = icmp eq i32 %86, %88
%90 = zext i1 %89 to i32
%91 = call i32 @assert(i32 %90)
%92 = call i32 @mx_strtoul(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i64* %1)
%93 = load i32, i32* @EINVAL
%94 = sub nsw i32 0, %93
%95 = icmp eq i32 %92, %94
%96 = zext i1 %95 to i32
%97 = call i32 @assert(i32 %96)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"123\00"
@.str.1 = [8 x i8] c" 123 \00"
@.str.2 = [5 x i8] c"0173\00"
@.str.3 = [7 x i8] c"0x007b\00"
@.str.4 = [7 x i8] c"0x007B\00"
@.str.5 = [5 x i8] c"+123\00"
@.str.6 = [3 x i8] c"-1\00"
@ERANGE = global i32 0
@.str.7 = [4 x i8] c" -1\00"
@.str.8 = [8 x i8] c"123 123\00"
@EINVAL = global i32 0
@.str.9 = [5 x i8] c"123s\00"
@.str.10 = [5 x i8] c"0888\00"
@.str.11 = [4 x i8] c"1.2\00"
@.str.12 = [4 x i8] c"1,2\00"
@.str.13 = [5 x i8] c"test\00"
define void @test_mx_strtoul() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32 @mx_strtoul(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%4 = icmp eq i32 %3, 0
%5 = zext i1 %4 to i32
%6 = call i32 @assert(i32 %5)
%7 = load i64, i64* %1
%8 = icmp eq i64 %7, 123
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i32 @mx_strtoul(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i64, i64* %1
%16 = icmp eq i64 %15, 123
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i32 @mx_strtoul(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i64, i64* %1
%24 = icmp eq i64 %23, 123
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = call i32 @mx_strtoul(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64* %1)
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i64, i64* %1
%32 = icmp eq i64 %31, 123
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = call i32 @mx_strtoul(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i64* %1)
%36 = icmp eq i32 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i64, i64* %1
%40 = icmp eq i64 %39, 123
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = call i32 @mx_strtoul(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64* %1)
%44 = icmp eq i32 %43, 0
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = load i64, i64* %1
%48 = icmp eq i64 %47, 123
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = call i32 @mx_strtoul(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64* %1)
%52 = load i32, i32* @ERANGE
%53 = sub nsw i32 0, %52
%54 = icmp eq i32 %51, %53
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
%57 = call i32 @mx_strtoul(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i64* %1)
%58 = load i32, i32* @ERANGE
%59 = sub nsw i32 0, %58
%60 = icmp eq i32 %57, %59
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
%63 = call i32 @mx_strtoul(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i64* %1)
%64 = load i32, i32* @EINVAL
%65 = sub nsw i32 0, %64
%66 = icmp eq i32 %63, %65
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = call i32 @mx_strtoul(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i64* %1)
%70 = load i32, i32* @EINVAL
%71 = sub nsw i32 0, %70
%72 = icmp eq i32 %69, %71
%73 = zext i1 %72 to i32
%74 = call i32 @assert(i32 %73)
%75 = call i32 @mx_strtoul(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i64* %1)
%76 = load i32, i32* @EINVAL
%77 = sub nsw i32 0, %76
%78 = icmp eq i32 %75, %77
%79 = zext i1 %78 to i32
%80 = call i32 @assert(i32 %79)
%81 = call i32 @mx_strtoul(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i64* %1)
%82 = load i32, i32* @EINVAL
%83 = sub nsw i32 0, %82
%84 = icmp eq i32 %81, %83
%85 = zext i1 %84 to i32
%86 = call i32 @assert(i32 %85)
%87 = call i32 @mx_strtoul(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i64* %1)
%88 = load i32, i32* @EINVAL
%89 = sub nsw i32 0, %88
%90 = icmp eq i32 %87, %89
%91 = zext i1 %90 to i32
%92 = call i32 @assert(i32 %91)
%93 = call i32 @mx_strtoul(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), i64* %1)
%94 = load i32, i32* @EINVAL
%95 = sub nsw i32 0, %94
%96 = icmp eq i32 %93, %95
%97 = zext i1 %96 to i32
%98 = call i32 @assert(i32 %97)
ret void
}