#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);
scalar_t__ strtol(char const *const, char **, int /*<<< orphan*/);
char const *parse_int(char const *const str, int *const valp) {
  char *endp;
  assert(str && "parse_int(): str == NULL");
  *valp = (int)strtol(str, &endp, 0);
  if (str == endp) {
    return NULL;
  }
  return endp;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x21(%rbp)
je     114a <parse_int+0x2a>
mov    $0x1,%al
mov    %al,-0x21(%rbp)
jmp    114a <parse_int+0x2a>
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1189 <parse_int+0x69>
movq   $0x0,-0x8(%rbp)
jmp    1191 <parse_int+0x71>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1030 <assert@plt>
lea    0x8(%rsp),%rsi
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,(%r14)
mov    0x8(%rsp),%rax
cmp    %r15,%rax
cmovne %rax,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @parse_int(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp ne i8* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = call i64 @strtol(i8* %0, i8** %3, i32 0)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %1
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, %0
%12 = select i1 %11, i8* null, i8* %10
ret i8* %12
}