#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 */
scalar_t__ errno;
scalar_t__ strcmp(char *, char const *);
char *strtok(char *, char *);
long strtol(char *, char **, int);
int /*<<< orphan*/ warn(char *);
int parse_long(char *line, const char *key, long *result) {
  char *value;
  char *notconv;
  if (strcmp(strtok(line, "="), key) == 0) {
    if ((value = strtok(NULL, "\n")) == NULL) {
      warn("strtok");
      return -1;
    }
    errno = 0;
    *result = strtol(value, &notconv, 10);
    if (errno != 0 || *notconv != '\0') {
      warn("strtol");
      return -1;
    }
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<parse_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    121f <parse_long+0xdf>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe7d(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b0 <parse_long+0x70>
lea    0xe65(%rip),%rdi
call   1030 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1226 <parse_long+0xe6>
mov    0x2e29(%rip),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2dff(%rip),%rax
cmpq   $0x0,(%rax)
jne    11fb <parse_long+0xbb>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1213 <parse_long+0xd3>
lea    0xe09(%rip),%rdi
call   1030 <warn@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1226 <parse_long+0xe6>
movl   $0x0,-0x4(%rbp)
jmp    1226 <parse_long+0xe6>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_long>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xeaa(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    11cd <parse_long+0x8d>
lea    0xe8b(%rip),%rsi
xor    %edi,%edi
call   1060 <strtok@plt>
test   %rax,%rax
je     11c1 <parse_long+0x81>
mov    0x2e56(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,(%r14)
lea    0xe5e(%rip),%rdi
cmpq   $0x0,(%r15)
jne    11c8 <parse_long+0x88>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    11c8 <parse_long+0x88>
xor    %ebx,%ebx
jmp    11cd <parse_long+0x8d>
lea    0xe3c(%rip),%rdi
call   1030 <warn@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"=\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [7 x i8] c"strtok\00"
@errno = global i64 0
@.str.3 = [7 x i8] c"strtol\00"
define i32 @parse_long(i8* %0, i8* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64* %2, i64** %7
%10 = load i8*, i8** %5
%11 = call i8* @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = load i8*, i8** %6
%13 = call i64 @strcmp(i8* %11, i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %34
15: ; preds = %3
%16 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %8
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %35
20: ; preds = %15
store i64 0, i64* @errno
%21 = load i8*, i8** %8
%22 = call i64 @strtol(i8* %21, i8** %9, i32 10)
%23 = load i64*, i64** %7
store i64 %22, i64* %23
%24 = load i64, i64* @errno
%25 = icmp ne i64 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %20
%27 = load i8*, i8** %9
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26, %20
%32 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %4
br label %35
33: ; preds = %26
store i32 0, i32* %4
br label %35
34: ; preds = %3
store i32 -1, i32* %4
br label %35
35: ; preds = %34, %33, %31, %18
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@.str = [2 x i8] c"=\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [7 x i8] c"strtok\00"
@errno = global i64 0
@.str.3 = [7 x i8] c"strtol\00"
define i32 @parse_long(i8* %0, i8* %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i64 @strcmp(i8* %6, i8* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %3
%10 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %20, label %12
12: ; preds = %9
store i64 0, i64* @errno
%13 = call i64 @strtol(i8* %10, i8** %4, i32 10)
store i64 %13, i64* %2
%14 = load i64, i64* @errno
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %12, %16, %9
%21 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %9 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %16 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %12 ]
%22 = tail call i32 @warn(i8* %21)
br label %23
23: ; preds = %20, %3, %16
%24 = phi i32 [ 0, %16 ], [ -1, %3 ], [ -1, %20 ]
ret i32 %24
}