#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ blast(int /*<<< orphan*/ *, char const *, long, long);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, long *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ panic(char *);
scalar_t__ strcmp(char const *, char *);
size_t strlen(char *);
int /*<<< orphan*/ sys_panic(char const *);
void ark_get(FILE *ark, const char *ark_name, const char *key) {
  if (0 != fseek(ark, -11, SEEK_END))
    sys_panic(ark_name);
  long catalog_size;
  fscanf(ark, "%ld", &catalog_size);
  if (catalog_size <= 0)
    panic("Bad or empty arkfile");
  if (0 != fseek(ark, -11 - catalog_size, SEEK_END))
    sys_panic(ark_name);
  long offset = 0;
  for (;;) {
    long size;
    fscanf(ark, "%ld ", &size);
    char key2[1024];
    if (!fgets(key2, sizeof key2, ark))
      panic("Key not found");
    size_t L = strlen(key2);
    if (0 < L)
      key2[L - 1] = '\0';
    if (0 == strcmp(key, key2)) {
      blast(ark, ark_name, offset, size);
      return;
    }
    offset += size;
  }
}


x86 assembly (clang, -O0):
<ark_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff5,%esi
call   1090 <fseek@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11c5 <ark_get+0x45>
mov    -0x10(%rbp),%rdi
call   1030 <sys_panic@plt>
mov    -0x8(%rbp),%rdi
lea    0xe30(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <fscanf@plt>
cmpq   $0x0,-0x20(%rbp)
jg     11f0 <ark_get+0x70>
lea    0xe19(%rip),%rdi
call   1050 <panic@plt>
mov    -0x8(%rbp),%rdi
mov    $0xfffffffffffffff5,%rax
sub    -0x20(%rbp),%rax
mov    %eax,%esi
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1226 <ark_get+0xa6>
mov    -0x10(%rbp),%rdi
call   1030 <sys_panic@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xde0(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <fscanf@plt>
lea    -0x430(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%eax
jne    126c <ark_get+0xec>
lea    0xdb7(%rip),%rdi
call   1050 <panic@plt>
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x438(%rbp)
xor    %eax,%eax
cmp    -0x438(%rbp),%rax
jae    12a1 <ark_get+0x121>
mov    -0x438(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x430(%rbp,%rax,1)
mov    -0x18(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1080 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12dd <ark_get+0x15d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   10a0 <blast@plt>
add    $0x440,%rsp
pop    %rbp
ret
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    122e <ark_get+0xae>

x86 assembly (clang, -O2):
<ark_get>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%r12
mov    0x2e47(%rip),%rbx
mov    (%rbx),%edx
mov    $0xfffffff5,%esi
call   1090 <fseek@plt>
test   %rax,%rax
je     11ba <ark_get+0x3a>
mov    %rbp,%rdi
call   1030 <sys_panic@plt>
lea    0xe3f(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r12,%rdi
call   1060 <fscanf@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
jg     11e9 <ark_get+0x69>
lea    0xe25(%rip),%rdi
call   1050 <panic@plt>
mov    0x8(%rsp),%rax
mov    $0xfffffff5,%esi
sub    %eax,%esi
mov    (%rbx),%edx
mov    %r12,%rdi
call   1090 <fseek@plt>
test   %rax,%rax
je     1207 <ark_get+0x87>
mov    %rbp,%rdi
call   1030 <sys_panic@plt>
mov    %rbp,0x10(%rsp)
xor    %ebx,%ebx
lea    0xe04(%rip),%r13
lea    0x18(%rsp),%rbp
lea    0x20(%rsp),%r14
nop
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <fscanf@plt>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %eax,%eax
jne    124e <ark_get+0xce>
lea    0xdd5(%rip),%rdi
call   1050 <panic@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     1261 <ark_get+0xe1>
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
mov    0x18(%rsp),%rcx
test   %rax,%rax
je     127b <ark_get+0xfb>
add    %rcx,%rbx
jmp    1220 <ark_get+0xa0>
mov    %r12,%rdi
mov    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   10a0 <blast@plt>
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [4 x i8] c"%ld\00"
@.str.1 = [21 x i8] c"Bad or empty arkfile\00"
@.str.2 = [5 x i8] c"%ld \00"
@.str.3 = [14 x i8] c"Key not found\00"
define void @ark_get(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca [1024 x i8]
%11 = alloca i64
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i32*, i32** %4
%13 = load i32, i32* @SEEK_END
%14 = call i64 @fseek(i32* %12, i32 -11, i32 %13)
%15 = icmp ne i64 0, %14
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call i32 @sys_panic(i8* %17)
br label %19
19: ; preds = %16, %3
%20 = load i32*, i32** %4
%21 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %7)
%22 = load i64, i64* %7
%23 = icmp sle i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
%27 = load i32*, i32** %4
%28 = load i64, i64* %7
%29 = sub nsw i64 -11, %28
%30 = trunc i64 %29 to i32
%31 = load i32, i32* @SEEK_END
%32 = call i64 @fseek(i32* %27, i32 %30, i32 %31)
%33 = icmp ne i64 0, %32
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = load i8*, i8** %5
%36 = call i32 @sys_panic(i8* %35)
br label %37
37: ; preds = %34, %26
store i64 0, i64* %8
br label %38
38: ; preds = %67, %37
%39 = load i32*, i32** %4
%40 = call i32 @fscanf(i32* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %9)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%42 = load i32*, i32** %4
%43 = call i32 @fgets(i8* %41, i32 1024, i32* %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %38
%46 = call i32 @panic(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %38
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%49 = call i64 @strlen(i8* %48)
store i64 %49, i64* %11
%50 = load i64, i64* %11
%51 = icmp ult i64 0, %50
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i64, i64* %11
%54 = sub i64 %53, 1
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %54
store i8 0, i8* %55
br label %56
56: ; preds = %52, %47
%57 = load i8*, i8** %6
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%59 = call i64 @strcmp(i8* %57, i8* %58)
%60 = icmp eq i64 0, %59
br i1 %60, label %61, label %67
61: ; preds = %56
%62 = load i32*, i32** %4
%63 = load i8*, i8** %5
%64 = load i64, i64* %8
%65 = load i64, i64* %9
%66 = call i32 @blast(i32* %62, i8* %63, i64 %64, i64 %65)
ret void
67: ; preds = %56
%68 = load i64, i64* %9
%69 = load i64, i64* %8
%70 = add nsw i64 %69, %68
store i64 %70, i64* %8
br label %38
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [4 x i8] c"%ld\00"
@.str.1 = [21 x i8] c"Bad or empty arkfile\00"
@.str.2 = [5 x i8] c"%ld \00"
@.str.3 = [14 x i8] c"Key not found\00"
define void @ark_get(i32* %0, i8* %1, i8* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca [1024 x i8]
%7 = load i32, i32* @SEEK_END
%8 = tail call i64 @fseek(i32* %0, i32 -11, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = tail call i32 @sys_panic(i8* %1)
br label %12
12: ; preds = %10, %3
%13 = bitcast i64* %4 to i8*
%14 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %4)
%15 = load i64, i64* %4
%16 = icmp slt i64 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = call i32 @panic(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%19 = load i64, i64* %4
br label %20
20: ; preds = %17, %12
%21 = phi i64 [ %19, %17 ], [ %15, %12 ]
%22 = trunc i64 %21 to i32
%23 = sub i32 -11, %22
%24 = load i32, i32* @SEEK_END
%25 = call i64 @fseek(i32* %0, i32 %23, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %20
%28 = call i32 @sys_panic(i8* %1)
br label %29
29: ; preds = %27, %20
%30 = bitcast i64* %5 to i8*
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
br label %32
32: ; preds = %49, %29
%33 = phi i64 [ 0, %29 ], [ %50, %49 ]
%34 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64* %5)
%35 = call i32 @fgets(i8* %31, i32 1024, i32* %0)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @panic(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %32
%40 = call i64 @strlen(i8* %31)
%41 = icmp eq i64 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = add i64 %40, -1
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %42, %39
%46 = call i64 @strcmp(i8* %2, i8* %31)
%47 = icmp eq i64 %46, 0
%48 = load i64, i64* %5
br i1 %47, label %51, label %49
49: ; preds = %45
%50 = add nsw i64 %48, %33
br label %32
51: ; preds = %45
%52 = call i32 @blast(i32* %0, i8* %1, i64 %33, i64 %48)
ret void
}