#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 /*<<< orphan*/ free(char *);
unsigned int pgheader_read_raw(char **, char const *, unsigned int *);
int pgheader_read(char **header, const char *infile) {
  unsigned int size, ret;
  int i;
  ret = pgheader_read_raw(header, infile, &size);
  if (ret) {
    return ret;
  }
  if (size == 0) {
    free(*header);
    *header = NULL;
    return 3;
  }
  for (i = 0; i < size; i++) {
    if ((*header)[i] == '\0') {
      return 0;
    }
  }
  free(*header);
  (*header) = NULL;
  return 6;
}


x86 assembly (clang, -O0):
<pgheader_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <pgheader_read_raw@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1159 <pgheader_read+0x39>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ee <pgheader_read+0xce>
cmpl   $0x0,-0x1c(%rbp)
jne    1186 <pgheader_read+0x66>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x3,-0x4(%rbp)
jmp    11ee <pgheader_read+0xce>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11d0 <pgheader_read+0xb0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11bd <pgheader_read+0x9d>
movl   $0x0,-0x4(%rbp)
jmp    11ee <pgheader_read+0xce>
jmp    11c2 <pgheader_read+0xa2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118d <pgheader_read+0x6d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x6,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgheader_read>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rdx
call   1040 <pgheader_read_raw@plt>
test   %eax,%eax
jne    117c <pgheader_read+0x5c>
mov    0xc(%rsp),%ecx
mov    (%rbx),%rdi
test   %rcx,%rcx
je     116b <pgheader_read+0x4b>
xor    %eax,%eax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x0,(%rdi,%rdx,1)
je     117c <pgheader_read+0x5c>
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1150 <pgheader_read+0x30>
call   1030 <free@plt>
mov    $0x6,%eax
jmp    1175 <pgheader_read+0x55>
call   1030 <free@plt>
mov    $0x3,%eax
movq   $0x0,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @pgheader_read(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %5
%11 = call i32 @pgheader_read_raw(i8** %9, i8* %10, i32* %6)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* %7
store i32 %15, i32* %3
br label %48
16: ; preds = %2
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8**, i8*** %4
%21 = load i8*, i8** %20
%22 = call i32 @free(i8* %21)
%23 = load i8**, i8*** %4
store i8* null, i8** %23
store i32 3, i32* %3
br label %48
24: ; preds = %16
store i32 0, i32* %8
br label %25
25: ; preds = %40, %24
%26 = load i32, i32* %8
%27 = load i32, i32* %6
%28 = icmp ult i32 %26, %27
br i1 %28, label %29, label %43
29: ; preds = %25
%30 = load i8**, i8*** %4
%31 = load i8*, i8** %30
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %29
store i32 0, i32* %3
br label %48
39: ; preds = %29
br label %40
40: ; preds = %39
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %25
43: ; preds = %25
%44 = load i8**, i8*** %4
%45 = load i8*, i8** %44
%46 = call i32 @free(i8* %45)
%47 = load i8**, i8*** %4
store i8* null, i8** %47
store i32 6, i32* %3
br label %48
48: ; preds = %43, %38, %19, %14
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
define i32 @pgheader_read(i8** %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @pgheader_read_raw(i8** %0, i8* %1, i32* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %27
7: ; preds = %2
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
%10 = load i8*, i8** %0
br i1 %9, label %13, label %11
11: ; preds = %7
%12 = zext i32 %8 to i64
br label %17
13: ; preds = %7
%14 = call i32 @free(i8* %10)
br label %25
15: ; preds = %17
%16 = icmp eq i64 %22, %12
br i1 %16, label %23, label %17
17: ; preds = %11, %15
%18 = phi i64 [ 0, %11 ], [ %22, %15 ]
%19 = getelementptr inbounds i8, i8* %10, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
%22 = add nuw nsw i64 %18, 1
br i1 %21, label %27, label %15
23: ; preds = %15
%24 = call i32 @free(i8* %10)
br label %25
25: ; preds = %13, %23
%26 = phi i32 [ 6, %23 ], [ 3, %13 ]
store i8* null, i8** %0
br label %27
27: ; preds = %17, %25, %2
%28 = phi i32 [ %5, %2 ], [ %26, %25 ], [ 0, %17 ]
ret i32 %28
}