#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*/ assert(int);
int scan_ulong(char *, unsigned long *);
int main() {
  unsigned long l;
  assert(scan_ulong("12345", &l) == 5 && l == 12345);
  assert(scan_ulong("-12345", &l) == 0);
  assert(scan_ulong("4294967295", &l) == 10 && l == 4294967295ul);
  if (sizeof(unsigned long) == 4) {
    assert(scan_ulong("4294967296", &l) == 9 && l == 429496729);
    assert(scan_ulong("42949672950", &l) == 10 && l == 4294967295ul);
    assert(scan_ulong("5294967295", &l) == 9 && l == 529496729);
    assert(scan_ulong("4295067295", &l) == 9 && l == 429506729);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecb(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <scan_ulong@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x5,%ecx
mov    %al,-0x11(%rbp)
jne    115d <main+0x3d>
cmpq   $0x3039,-0x10(%rbp)
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe8f(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <scan_ulong@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe76(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <scan_ulong@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x12(%rbp)
jne    11b9 <main+0x99>
mov    $0xffffffff,%eax
cmp    %rax,-0x10(%rbp)
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xed5(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1030 <scan_ulong@plt>
cmp    $0x5,%eax
sete   %al
cmpq   $0x3039,0x8(%rsp)
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
lea    0xea4(%rip),%rdi
mov    %rbx,%rsi
call   1030 <scan_ulong@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
lea    0xe8f(%rip),%rdi
mov    %rbx,%rsi
call   1030 <scan_ulong@plt>
cmp    $0xa,%eax
sete   %al
mov    $0xffffffff,%ecx
cmp    %rcx,0x8(%rsp)
sete   %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"12345\00"
@.str.1 = [7 x i8] c"-12345\00"
@.str.2 = [11 x i8] c"4294967295\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i32 @scan_ulong(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %2)
%4 = icmp eq i32 %3, 5
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i64, i64* %2
%7 = icmp eq i64 %6, 12345
br label %8
8: ; preds = %5, %0
%9 = phi i1 [ false, %0 ], [ %7, %5 ]
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = call i32 @scan_ulong(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 @scan_ulong(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %21
18: ; preds = %8
%19 = load i64, i64* %2
%20 = icmp eq i64 %19, 4294967295
br label %21
21: ; preds = %18, %8
%22 = phi i1 [ false, %8 ], [ %20, %18 ]
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"12345\00"
@.str.1 = [7 x i8] c"-12345\00"
@.str.2 = [11 x i8] c"4294967295\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32 @scan_ulong(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %1)
%4 = icmp eq i32 %3, 5
%5 = load i64, i64* %1
%6 = icmp eq i64 %5, 12345
%7 = select i1 %4, i1 %6, i1 false
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = call i32 @scan_ulong(i8* getelementptr inbounds ([7 x i8], [7 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 = call i32 @scan_ulong(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%15 = icmp eq i32 %14, 10
%16 = load i64, i64* %1
%17 = icmp eq i64 %16, 4294967295
%18 = select i1 %15, i1 %17, i1 false
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
ret i32 0
}