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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, scalar_t__, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int read_compressed_int(int /*<<< orphan*/ *);
int seek_definition(int /*<<< orphan*/ *, char *);
scalar_t__ strlen(char *);
int read_array(FILE *f, char *config_path, char *buffer, int size,
               size_t buffsize) {
  int i;
  int success;
  long fp;
  uint8_t temp;
  uint32_t num_entries;
  success = seek_definition(f, config_path);
  if (success != 0)
    return success;
  temp = fgetc(f);
  if (temp != 2)
    return 1;
  while (fgetc(f) != 0)
    ;
  num_entries = read_compressed_int(f);
  for (i = 0; i < num_entries; i++) {
    if (i == size)
      return 2;
    temp = fgetc(f);
    if (temp != 0)
      return 3;
    fp = ftell(f);
    if (fgets(buffer + i * buffsize, buffsize, f) == NULL)
      return 3;
    fseek(f, fp + strlen(buffer + i * buffsize) + 1, SEEK_SET);
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <seek_definition@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     11b0 <read_array+0x40>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12de <read_array+0x16e>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x2,-0x44(%rbp)
je     11d2 <read_array+0x62>
movl   $0x1,-0x4(%rbp)
jmp    12de <read_array+0x16e>
jmp    11d7 <read_array+0x67>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
cmp    $0x0,%eax
je     11ee <read_array+0x7e>
jmp    11d7 <read_array+0x67>
mov    -0x10(%rbp),%rdi
call   1070 <read_compressed_int@plt>
mov    %eax,-0x48(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x48(%rbp),%eax
jge    12d7 <read_array+0x167>
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    1225 <read_array+0xb5>
movl   $0x2,-0x4(%rbp)
jmp    12de <read_array+0x16e>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     1247 <read_array+0xd7>
movl   $0x3,-0x4(%rbp)
jmp    12de <read_array+0x16e>
mov    -0x10(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x34(%rbp),%rax
imul   -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1287 <read_array+0x117>
movl   $0x3,-0x4(%rbp)
jmp    12de <read_array+0x16e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x34(%rbp),%rax
imul   -0x30(%rbp),%rax
add    %rax,%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rsi
mov    -0x50(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
mov    0x2d1e(%rip),%rax
mov    (%rax),%edx
call   1090 <fseek@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1201 <read_array+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %rdi,%rbx
call   1060 <seek_definition@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1252 <read_array+0xe2>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    $0x1,%ebp
cmp    $0x2,%eax
jne    1252 <read_array+0xe2>
nop
mov    %rbx,%rdi
call   1040 <fgetc@plt>
test   %eax,%eax
jne    11b0 <read_array+0x40>
mov    %rbx,%rdi
call   1070 <read_compressed_int@plt>
test   %eax,%eax
jle    1249 <read_array+0xd9>
mov    %r12d,%ecx
mov    %rcx,0x10(%rsp)
mov    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
xchg   %ax,%ax
cmp    %r13,0x10(%rsp)
je     124d <read_array+0xdd>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    $0x3,%ebp
test   %eax,%eax
jne    1252 <read_array+0xe2>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1252 <read_array+0xe2>
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    (%r12,%rax,1),%rsi
add    $0x1,%rsi
mov    0x2db3(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1090 <fseek@plt>
add    $0x1,%r13
add    %r14,%r15
xor    %ebp,%ebp
cmp    %r13,0x8(%rsp)
jne    11e0 <read_array+0x70>
jmp    1252 <read_array+0xe2>
xor    %ebp,%ebp
jmp    1252 <read_array+0xe2>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @read_array(i32* %0, i8* %1, i8* %2, i32 %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i64 %4, i64* %11
%17 = load i32*, i32** %7
%18 = load i8*, i8** %8
%19 = call i32 @seek_definition(i32* %17, i8* %18)
store i32 %19, i32* %13
%20 = load i32, i32* %13
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %5
%23 = load i32, i32* %13
store i32 %23, i32* %6
br label %86
24: ; preds = %5
%25 = load i32*, i32** %7
%26 = call i32 @fgetc(i32* %25)
store i32 %26, i32* %15
%27 = load i32, i32* %15
%28 = icmp ne i32 %27, 2
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 1, i32* %6
br label %86
30: ; preds = %24
br label %31
31: ; preds = %35, %30
%32 = load i32*, i32** %7
%33 = call i32 @fgetc(i32* %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
br label %31
36: ; preds = %31
%37 = load i32*, i32** %7
%38 = call i32 @read_compressed_int(i32* %37)
store i32 %38, i32* %16
store i32 0, i32* %12
br label %39
39: ; preds = %82, %36
%40 = load i32, i32* %12
%41 = load i32, i32* %16
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %85
43: ; preds = %39
%44 = load i32, i32* %12
%45 = load i32, i32* %10
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %43
store i32 2, i32* %6
br label %86
48: ; preds = %43
%49 = load i32*, i32** %7
%50 = call i32 @fgetc(i32* %49)
store i32 %50, i32* %15
%51 = load i32, i32* %15
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %48
store i32 3, i32* %6
br label %86
54: ; preds = %48
%55 = load i32*, i32** %7
%56 = call i64 @ftell(i32* %55)
store i64 %56, i64* %14
%57 = load i8*, i8** %9
%58 = load i32, i32* %12
%59 = sext i32 %58 to i64
%60 = load i64, i64* %11
%61 = mul i64 %59, %60
%62 = getelementptr inbounds i8, i8* %57, i64 %61
%63 = load i64, i64* %11
%64 = load i32*, i32** %7
%65 = call i32* @fgets(i8* %62, i64 %63, i32* %64)
%66 = icmp eq i32* %65, null
br i1 %66, label %67, label %68
67: ; preds = %54
store i32 3, i32* %6
br label %86
68: ; preds = %54
%69 = load i32*, i32** %7
%70 = load i64, i64* %14
%71 = load i8*, i8** %9
%72 = load i32, i32* %12
%73 = sext i32 %72 to i64
%74 = load i64, i64* %11
%75 = mul i64 %73, %74
%76 = getelementptr inbounds i8, i8* %71, i64 %75
%77 = call i64 @strlen(i8* %76)
%78 = add nsw i64 %70, %77
%79 = add nsw i64 %78, 1
%80 = load i32, i32* @SEEK_SET
%81 = call i32 @fseek(i32* %69, i64 %79, i32 %80)
br label %82
82: ; preds = %68
%83 = load i32, i32* %12
%84 = add nsw i32 %83, 1
store i32 %84, i32* %12
br label %39
85: ; preds = %39
store i32 0, i32* %6
br label %86
86: ; preds = %85, %67, %53, %47, %29, %22
%87 = load i32, i32* %6
ret i32 %87
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @read_array(i32* %0, i8* %1, i8* %2, i32 %3, i64 %4) {
%6 = tail call i32 @seek_definition(i32* %0, i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %40
8: ; preds = %5
%9 = tail call i32 @fgetc(i32* %0)
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %40
11: ; preds = %8, %11
%12 = tail call i32 @fgetc(i32* %0)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %11
14: ; preds = %11
%15 = tail call i32 @read_compressed_int(i32* %0)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %40
17: ; preds = %14
%18 = zext i32 %3 to i64
%19 = zext i32 %15 to i64
br label %20
20: ; preds = %17, %32
%21 = phi i64 [ 0, %17 ], [ %38, %32 ]
%22 = icmp eq i64 %21, %18
br i1 %22, label %40, label %23
23: ; preds = %20
%24 = tail call i32 @fgetc(i32* %0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %40
26: ; preds = %23
%27 = tail call i64 @ftell(i32* %0)
%28 = mul i64 %21, %4
%29 = getelementptr inbounds i8, i8* %2, i64 %28
%30 = tail call i32* @fgets(i8* %29, i64 %4, i32* %0)
%31 = icmp eq i32* %30, null
br i1 %31, label %40, label %32
32: ; preds = %26
%33 = tail call i64 @strlen(i8* dereferenceable(1) %29)
%34 = add i64 %27, 1
%35 = add i64 %34, %33
%36 = load i32, i32* @SEEK_SET
%37 = tail call i32 @fseek(i32* %0, i64 %35, i32 %36)
%38 = add nuw nsw i64 %21, 1
%39 = icmp eq i64 %38, %19
br i1 %39, label %40, label %20
40: ; preds = %20, %23, %26, %32, %14, %8, %5
%41 = phi i32 [ %6, %5 ], [ 1, %8 ], [ 0, %14 ], [ 2, %20 ], [ 3, %23 ], [ 3, %26 ], [ 0, %32 ]
ret i32 %41
}