#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 */
struct lh_kv_elem {
  int dummy;
};
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
char *lh_kv_string(struct lh_kv_elem const *, char const *,
                   int /*<<< orphan*/ *);
int /*<<< orphan*/ strtoll(char const *, char **, int /*<<< orphan*/);
int64_t lh_kv_int64(const struct lh_kv_elem *kvs, const char *key, int *error) {
  const char *str = lh_kv_string(kvs, key, NULL);
  if (!str) {
    if (error)
      *error = 1;
    return 0;
  }
  char *pEnd = NULL;
  int64_t n = (int64_t)strtoll(str, &pEnd, 0);
  if ((*str != '\0' && *pEnd == '\0'))
    return n;
  if (error)
    *error = 1;
  return 0;
  ;
}


x86 assembly (clang, -O0):
<lh_kv_int64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <lh_kv_string@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1175 <lh_kv_int64+0x55>
cmpq   $0x0,-0x20(%rbp)
je     1169 <lh_kv_int64+0x49>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d6 <lh_kv_int64+0xb6>
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ba <lh_kv_int64+0x9a>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ba <lh_kv_int64+0x9a>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d6 <lh_kv_int64+0xb6>
cmpq   $0x0,-0x20(%rbp)
je     11cf <lh_kv_int64+0xaf>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lh_kv_int64>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
xor    %r15d,%r15d
xor    %edx,%edx
call   1040 <lh_kv_string@plt>
test   %rax,%rax
je     1168 <lh_kv_int64+0x48>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
xor    %r15d,%r15d
mov    %rax,%rdi
xor    %edx,%edx
call   1030 <strtoll@plt>
cmpb   $0x0,(%rbx)
je     1168 <lh_kv_int64+0x48>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
je     1176 <lh_kv_int64+0x56>
test   %r14,%r14
je     1179 <lh_kv_int64+0x59>
movl   $0x1,(%r14)
jmp    1179 <lh_kv_int64+0x59>
mov    %eax,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.lh_kv_elem = type { i32 }
define i32 @lh_kv_int64(%struct.lh_kv_elem* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca %struct.lh_kv_elem*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store %struct.lh_kv_elem* %0, %struct.lh_kv_elem** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%11 = load %struct.lh_kv_elem*, %struct.lh_kv_elem** %5
%12 = load i8*, i8** %6
%13 = call i8* @lh_kv_string(%struct.lh_kv_elem* %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 %22, label %16
16: ; preds = %3
%17 = load i32*, i32** %7
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i32*, i32** %7
store i32 1, i32* %20
br label %21
21: ; preds = %19, %16
store i32 0, i32* %4
br label %42
22: ; preds = %3
store i8* null, i8** %9
%23 = load i8*, i8** %8
%24 = call i32 @strtoll(i8* %23, i8** %9, i32 0)
store i32 %24, i32* %10
%25 = load i8*, i8** %8
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %22
%30 = load i8*, i8** %9
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i32, i32* %10
store i32 %35, i32* %4
br label %42
36: ; preds = %29, %22
%37 = load i32*, i32** %7
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = load i32*, i32** %7
store i32 1, i32* %40
br label %41
41: ; preds = %39, %36
store i32 0, i32* %4
br label %42
42: ; preds = %41, %34, %21
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
%struct.lh_kv_elem = type { i32 }
define i32 @lh_kv_int64(%struct.lh_kv_elem* %0, i8* %1, i32* writeonly %2) {
%4 = alloca i8*
%5 = tail call i8* @lh_kv_string(%struct.lh_kv_elem* %0, i8* %1, i32* null)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = icmp eq i32* %2, null
br i1 %8, label %24, label %9
9: ; preds = %7
store i32 1, i32* %2
br label %24
10: ; preds = %3
%11 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%12 = call i32 @strtoll(i8* %5, i8** %4, i32 0)
%13 = load i8, i8* %5
%14 = icmp eq i8 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15, %10
%20 = icmp eq i32* %2, null
br i1 %20, label %22, label %21
21: ; preds = %19
store i32 1, i32* %2
br label %22
22: ; preds = %19, %21, %15
%23 = phi i32 [ %12, %15 ], [ 0, %21 ], [ 0, %19 ]
br label %24
24: ; preds = %7, %9, %22
%25 = phi i32 [ %23, %22 ], [ 0, %9 ], [ 0, %7 ]
ret i32 %25
}