#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__ EINVAL;
scalar_t__ ERANGE;
char *GetHeaderString(char const *, char const *, int);
scalar_t__ errno;
long strtol(char *, int /*<<< orphan*/ *, int);
int GetHeaderLong(const char *buf, const char *header, int hdrsize,
                  long int *val) {
  long int temp_val;
  char *temp;
  if ((temp = GetHeaderString(buf, header, hdrsize)) != NULL) {
    temp_val = strtol(temp, NULL, 10);
    if (errno != ERANGE && errno != EINVAL) {
      *val = temp_val;
      return (1);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<GetHeaderLong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <GetHeaderString@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     11bb <GetHeaderLong+0x9b>
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
je     11b6 <GetHeaderLong+0x96>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
je     11b6 <GetHeaderLong+0x96>
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11c2 <GetHeaderLong+0xa2>
jmp    11bb <GetHeaderLong+0x9b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetHeaderLong>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
call   1030 <GetHeaderString@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     116c <GetHeaderLong+0x4c>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e95(%rip),%rdx
cmp    (%rdx),%rcx
je     116c <GetHeaderLong+0x4c>
mov    0x2e71(%rip),%rdx
cmp    (%rdx),%rcx
je     116c <GetHeaderLong+0x4c>
mov    %rax,(%r14)
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@EINVAL = global i64 0
define i32 @GetHeaderLong(i8* %0, i8* %1, i32 %2, i64* nocapture writeonly %3) {
%5 = tail call i8* @GetHeaderString(i8* %0, i8* %1, i32 %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %7
7: ; preds = %4
%8 = tail call i64 @strtol(i8* nocapture %5, i32* null, i32 10)
%9 = load i64, i64* @errno
%10 = load i64, i64* @ERANGE
%11 = icmp eq i64 %9, %10
%12 = load i64, i64* @EINVAL
%13 = icmp eq i64 %9, %12
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %16, label %15
15: ; preds = %7
store i64 %8, i64* %3
br label %16
16: ; preds = %4, %7, %15
%17 = phi i32 [ 1, %15 ], [ 0, %7 ], [ 0, %4 ]
ret i32 %17
}