#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*/ db_IndexGen(int /*<<< orphan*/ *);
int /*<<< orphan*/ db_err(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
short db_check(char filename[]) {
  FILE *database;
  int size, RowNum;
  char CtrlSig, data;
  char countX = 0, countY = 0;
  short temp;
  database = fopen(filename, "rt");
  if (database == NULL) {
    printf("Database Not Found! \n ");
    fclose(database);
    db_err(filename);
    return -1;
  } else {
    fseek(database, 0L, SEEK_END);
    size = ftell(database);
    if (size == 0) {
      printf("Database Empty!");
      fclose(database);
      db_err(filename);
      return -1;
    } else {
      db_IndexGen(database);
    }
  }
}


x86 assembly (clang, -O0):
<db_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movb   $0x0,-0x23(%rbp)
movb   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cc <db_check+0x5c>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1070 <db_err@plt>
movw   $0xffff,-0x2(%rbp)
jmp    122f <db_check+0xbf>
mov    -0x18(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1221 <db_check+0xb1>
lea    0xe1b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1070 <db_err@plt>
movw   $0xffff,-0x2(%rbp)
jmp    122f <db_check+0xbf>
mov    -0x18(%rbp),%rdi
call   1050 <db_IndexGen@plt>
jmp    122f <db_check+0xbf>
movswl -0x2(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_check>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe82(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11b4 <db_check+0x44>
mov    %rax,%rbx
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
test   %eax,%eax
je     11c4 <db_check+0x54>
mov    %rbx,%rdi
call   1050 <db_IndexGen@plt>
jmp    11e0 <db_check+0x70>
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
jmp    11d3 <db_check+0x63>
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1070 <db_err@plt>
mov    $0xffff,%ax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rt\00"
@.str.1 = [23 x i8] c"Database Not Found! \0A \00"
@SEEK_END = global i32 0
@.str.2 = [16 x i8] c"Database Empty!\00"
define signext i16 @db_check(i8* %0) {
%2 = alloca i16
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i16
store i8* %0, i8** %3
store i8 0, i8* %9
store i8 0, i8* %10
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %22
16: ; preds = %1
%17 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32*, i32** %4
%19 = call i32 @fclose(i32* %18)
%20 = load i8*, i8** %3
%21 = call i32 @db_err(i8* %20)
store i16 -1, i16* %2
br label %40
22: ; preds = %1
%23 = load i32*, i32** %4
%24 = load i32, i32* @SEEK_END
%25 = call i32 @fseek(i32* %23, i64 0, i32 %24)
%26 = load i32*, i32** %4
%27 = call i32 @ftell(i32* %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %22
%31 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
%34 = load i8*, i8** %3
%35 = call i32 @db_err(i8* %34)
store i16 -1, i16* %2
br label %40
36: ; preds = %22
%37 = load i32*, i32** %4
%38 = call i32 @db_IndexGen(i32* %37)
br label %39
39: ; preds = %36
br label %40
40: ; preds = %16, %30, %39
%41 = load i16, i16* %2
ret i16 %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
@.str.1 = [23 x i8] c"Database Not Found! \0A \00"
@SEEK_END = global i32 0
@.str.2 = [16 x i8] c"Database Empty!\00"
define signext i16 @db_check(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @fclose(i32* null)
%7 = tail call i32 @db_err(i8* %0)
br label %19
8: ; preds = %1
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %2, i64 0, i32 %9)
%11 = tail call i32 @ftell(i32* %2)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @fclose(i32* %2)
%16 = tail call i32 @db_err(i8* %0)
br label %19
17: ; preds = %8
%18 = tail call i32 @db_IndexGen(i32* %2)
br label %19
19: ; preds = %17, %13, %4
ret i16 -1
}