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

/* Variables and functions */
int /*<<< orphan*/ fopen(char *, char *);
int spkGenLUT(struct spkState *);
scalar_t__ spkLoadHeader(struct spkState *);
scalar_t__ spkSetArchive(struct spkState *, int /*<<< orphan*/);
int spkOpenArchive(struct spkState *state, char *filename) {
  if (spkSetArchive(state, fopen(filename, "rb")))
    return 1;
  if (spkLoadHeader(state))
    return 1;
  return spkGenLUT(state);
}


x86 assembly (clang, -O0):
<spkOpenArchive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1040 <fopen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1060 <spkSetArchive@plt>
cmp    $0x0,%rax
je     1189 <spkOpenArchive+0x49>
movl   $0x1,-0x4(%rbp)
jmp    11b4 <spkOpenArchive+0x74>
mov    -0x10(%rbp),%rdi
call   1050 <spkLoadHeader@plt>
cmp    $0x0,%rax
je     11a8 <spkOpenArchive+0x68>
movl   $0x1,-0x4(%rbp)
jmp    11b4 <spkOpenArchive+0x74>
mov    -0x10(%rbp),%rdi
call   1030 <spkGenLUT@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spkOpenArchive>:
push   %rbx
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xeb2(%rip),%rsi
mov    %rax,%rdi
call   1040 <fopen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <spkSetArchive@plt>
test   %rax,%rax
jne    1172 <spkOpenArchive+0x32>
mov    %rbx,%rdi
call   1050 <spkLoadHeader@plt>
test   %rax,%rax
je     1179 <spkOpenArchive+0x39>
mov    $0x1,%eax
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <spkGenLUT@plt>

LLVM IR (-O0):
%struct.spkState = type { i32 }
@.str = [3 x i8] c"rb\00"
define i32 @spkOpenArchive(%struct.spkState* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.spkState*
%5 = alloca i8*
store %struct.spkState* %0, %struct.spkState** %4
store i8* %1, i8** %5
%6 = load %struct.spkState*, %struct.spkState** %4
%7 = load i8*, i8** %5
%8 = call i32 @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = call i64 @spkSetArchive(%struct.spkState* %6, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %20
12: ; preds = %2
%13 = load %struct.spkState*, %struct.spkState** %4
%14 = call i64 @spkLoadHeader(%struct.spkState* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 1, i32* %3
br label %20
17: ; preds = %12
%18 = load %struct.spkState*, %struct.spkState** %4
%19 = call i32 @spkGenLUT(%struct.spkState* %18)
store i32 %19, i32* %3
br label %20
20: ; preds = %17, %16, %11
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.spkState = type { i32 }
@.str = [3 x i8] c"rb\00"
define i32 @spkOpenArchive(%struct.spkState* %0, i8* %1) {
%3 = tail call i32 @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @spkSetArchive(%struct.spkState* %0, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = tail call i64 @spkLoadHeader(%struct.spkState* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @spkGenLUT(%struct.spkState* %0)
br label %11
11: ; preds = %6, %2, %9
%12 = phi i32 [ %10, %9 ], [ 1, %2 ], [ 1, %6 ]
ret i32 %12
}