#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 */
char *get_item_as_string(char **, char *, int /*<<< orphan*/ *);
long strtol(char *, char **, int /*<<< orphan*/);
long get_item_as_long(char **str, char *trenner, int *result) {
  long v;
  char *s;
  int e;
  char *endptr;
  e = 0;
  v = 0L;
  s = get_item_as_string(str, trenner, NULL);
  if (!s)
    e = -1;
  else {
    v = strtol(s, (char **)&endptr, 0);
    if (s == endptr)
      e = -1;
  }
  if ((result))
    *(result) = (e);
  return (v);
}


x86 assembly (clang, -O0):
<get_item_as_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <get_item_as_string@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116f <get_item_as_long+0x4f>
movl   $0xffffffff,-0x2c(%rbp)
jmp    119c <get_item_as_long+0x7c>
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    1197 <get_item_as_long+0x77>
movl   $0xffffffff,-0x2c(%rbp)
jmp    119c <get_item_as_long+0x7c>
cmpq   $0x0,-0x18(%rbp)
je     11b0 <get_item_as_long+0x90>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_item_as_long>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
xor    %r15d,%r15d
xor    %edx,%edx
call   1030 <get_item_as_string@plt>
test   %rax,%rax
je     1171 <get_item_as_long+0x51>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%r15
xor    %eax,%eax
cmp    0x8(%rsp),%rbx
sete   %al
neg    %eax
test   %r14,%r14
je     1164 <get_item_as_long+0x44>
mov    %eax,(%r14)
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0xffffffff,%eax
test   %r14,%r14
jne    1161 <get_item_as_long+0x41>
jmp    1164 <get_item_as_long+0x44>

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

LLVM IR (-O2):
define i64 @get_item_as_long(i8** %0, i8* %1, i32* writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i8* @get_item_as_string(i8** %0, i8* %1, i32* null)
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = call i64 @strtol(i8* %6, i8** %4, i32 0)
%10 = load i8*, i8** %4
%11 = icmp eq i8* %6, %10
%12 = sext i1 %11 to i32
br label %13
13: ; preds = %8, %3
%14 = phi i64 [ 0, %3 ], [ %9, %8 ]
%15 = phi i32 [ -1, %3 ], [ %12, %8 ]
%16 = icmp eq i32* %2, null
br i1 %16, label %18, label %17
17: ; preds = %13
store i32 %15, i32* %2
br label %18
18: ; preds = %17, %13
ret i64 %14
}