#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 sscanf(char *, char *, int *);
scalar_t__ strncmp(char *, char *, int);
int gethdl(int *headl, char *head) {
  char temp[6], *hp, *tp;
  int i;
  if (strncmp("HEADER_BYTES=", head + 2, 12))
    return -2;
  for (i = 15, hp = head + 15, tp = temp; i < 20; i++)
    *tp++ = *hp++;
  *tp = 0;
  if (sscanf(temp, "%d", headl) != 1)
    *headl = 0;
  return 0;
}


x86 assembly (clang, -O0):
<gethdl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
add    $0x2,%rsi
lea    0xec1(%rip),%rdi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     115f <gethdl+0x3f>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11e9 <gethdl+0xc9>
movl   $0xf,-0x34(%rbp)
mov    -0x18(%rbp),%rax
add    $0xf,%rax
mov    %rax,-0x28(%rbp)
lea    -0x1e(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x14,-0x34(%rbp)
jge    11b4 <gethdl+0x94>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117a <gethdl+0x5a>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x1e(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe44(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     11e2 <gethdl+0xc2>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethdl>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0x2,%rsi
lea    0xecb(%rip),%rdi
mov    $0xc,%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
mov    $0xfffffffe,%eax
test   %rcx,%rcx
jne    1180 <gethdl+0x60>
mov    0x13(%rbx),%al
mov    %al,0x4(%rsp)
mov    0xf(%rbx),%eax
mov    %eax,(%rsp)
movb   $0x0,0x5(%rsp)
lea    0xea9(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
je     1180 <gethdl+0x60>
movl   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"HEADER_BYTES=\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @gethdl(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [6 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 2
%12 = call i64 @strncmp(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %11, i32 12)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -2, i32* %3
br label %40
15: ; preds = %2
store i32 15, i32* %9
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 15
store i8* %17, i8** %7
%18 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
store i8* %18, i8** %8
br label %19
19: ; preds = %28, %15
%20 = load i32, i32* %9
%21 = icmp slt i32 %20, 20
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %7
%25 = load i8, i8* %23
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %8
store i8 %25, i8* %26
br label %28
28: ; preds = %22
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
br label %19
31: ; preds = %19
%32 = load i8*, i8** %8
store i8 0, i8* %32
%33 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%34 = load i32*, i32** %4
%35 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %34)
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = load i32*, i32** %4
store i32 0, i32* %38
br label %39
39: ; preds = %37, %31
store i32 0, i32* %3
br label %40
40: ; preds = %39, %14
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [14 x i8] c"HEADER_BYTES=\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @gethdl(i32* %0, i8* %1) {
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8, i8* %1, i64 2
%6 = tail call i64 @strncmp(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %5, i32 12)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%10 = getelementptr i8, i8* %1, i64 15
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 5
store i8 0, i8* %11
%12 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %0)
%13 = icmp eq i32 %12, 1
br i1 %13, label %15, label %14
14: ; preds = %8
store i32 0, i32* %0
br label %15
15: ; preds = %8, %14, %2
%16 = phi i32 [ -2, %2 ], [ 0, %14 ], [ 0, %8 ]
ret i32 %16
}