#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 pt_cache_header {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ close(int);
int pt_cache_header_read(struct pt_cache_header *, int);
int pt_open_cache_read_fd(char const *, int *);
int pt_read_cache_header(const char *path, struct pt_cache_header *header) {
  int fd;
  int err;
  if ((err = pt_open_cache_read_fd(path, &fd)))
    return err;
  if ((err = pt_cache_header_read(header, fd)))
    goto error;
error:
  close(fd);
  return err;
}


x86 assembly (clang, -O0):
<pt_read_cache_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <pt_open_cache_read_fd@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     1164 <pt_read_cache_header+0x34>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <pt_read_cache_header+0x64>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <pt_cache_header_read@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     1181 <pt_read_cache_header+0x51>
jmp    1186 <pt_read_cache_header+0x56>
jmp    1186 <pt_read_cache_header+0x56>
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pt_read_cache_header>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0x4(%rsp),%rsi
call   1040 <pt_open_cache_read_fd@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    115d <pt_read_cache_header+0x2d>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1050 <pt_cache_header_read@plt>
mov    %eax,%ebp
mov    0x4(%rsp),%edi
call   1030 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.pt_cache_header = type { i32 }
define i32 @pt_read_cache_header(i8* %0, %struct.pt_cache_header* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.pt_cache_header*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store %struct.pt_cache_header* %1, %struct.pt_cache_header** %5
%8 = load i8*, i8** %4
%9 = call i32 @pt_open_cache_read_fd(i8* %8, i32* %6)
store i32 %9, i32* %7
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %7
store i32 %12, i32* %3
br label %24
13: ; preds = %2
%14 = load %struct.pt_cache_header*, %struct.pt_cache_header** %5
%15 = load i32, i32* %6
%16 = call i32 @pt_cache_header_read(%struct.pt_cache_header* %14, i32 %15)
store i32 %16, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
br label %20
19: ; preds = %13
br label %20
20: ; preds = %19, %18
%21 = load i32, i32* %6
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %24
24: ; preds = %20, %11
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.pt_cache_header = type { i32 }
define i32 @pt_read_cache_header(i8* %0, %struct.pt_cache_header* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @pt_open_cache_read_fd(i8* %0, i32* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* %3
%9 = call i32 @pt_cache_header_read(%struct.pt_cache_header* %1, i32 %8)
%10 = load i32, i32* %3
%11 = call i32 @close(i32 %10)
br label %12
12: ; preds = %2, %7
%13 = phi i32 [ %9, %7 ], [ %5, %2 ]
ret i32 %13
}