#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*/ exeknow_get_details_e32(int /*<<< orphan*/ *);
int /*<<< orphan*/ exeknow_get_details_elf(int /*<<< orphan*/ *);
int /*<<< orphan*/ exeknow_get_details_mz(int /*<<< orphan*/ *);
char *exeknow_getfilename(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int exeknow_get_details(FILE *fp, int ftype, const char *fname) {
  int ret = (0);
  fseek(fp, 0L, SEEK_END);
  fprintf(stdout, "------------\nFile Details:\n------------\n");
  fprintf(stdout, "Executable Name: %s\n", exeknow_getfilename(fname));
  fprintf(stdout, "Executable Size: %ld bytes\n", ftell(fp));
  fprintf(stdout, "Executable Type: ");
  switch (ftype) {
  case (1):
    fprintf(stdout, "MZ\n");
    exeknow_get_details_mz(fp);
    break;
  case (2):
    fprintf(stdout, "ELF\n");
    exeknow_get_details_elf(fp);
    break;
  case (3):
    fprintf(stdout, "E32\n");
    exeknow_get_details_e32(fp);
    break;
  default:
    fprintf(stdout, "Unknown\n");
    ret = (-4);
  }
  return ret;
}


x86 assembly (clang, -O0):
<exeknow_get_details>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x3c(%rbp),%eax
mov    0x2e2b(%rip),%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rcx),%edi
lea    0xe46(%rip),%rsi
mov    %al,-0x21(%rbp)
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <exeknow_getfilename@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
mov    -0x21(%rbp),%al
lea    0xe45(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <ftell@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%edx
mov    -0x21(%rbp),%al
lea    0xe34(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rcx
mov    -0x21(%rbp),%al
mov    (%rcx),%edi
lea    0xe3b(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x1,%eax
je     125a <exeknow_get_details+0xea>
jmp    1238 <exeknow_get_details+0xc8>
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
je     127f <exeknow_get_details+0x10f>
jmp    1249 <exeknow_get_details+0xd9>
mov    -0x20(%rbp),%eax
sub    $0x3,%eax
je     12a4 <exeknow_get_details+0x134>
jmp    12c9 <exeknow_get_details+0x159>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1090 <exeknow_get_details_mz@plt>
jmp    12e7 <exeknow_get_details+0x177>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <exeknow_get_details_elf@plt>
jmp    12e7 <exeknow_get_details+0x177>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <exeknow_get_details_e32@plt>
jmp    12e7 <exeknow_get_details+0x177>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xfffffffc,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exeknow_get_details>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %rdi,%r15
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
xor    %esi,%esi
call   1080 <fseek@plt>
mov    0x2e3a(%rip),%r13
mov    0x0(%r13),%edi
lea    0xe57(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%r13),%ebp
mov    %rbx,%rdi
call   1040 <exeknow_getfilename@plt>
lea    0xe66(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%r13),%ebx
mov    %r15,%rdi
call   1070 <ftell@plt>
lea    0xe5c(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe62(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
cmp    $0x3,%r12d
je     1230 <exeknow_get_details+0xc0>
cmp    $0x2,%r12d
je     124c <exeknow_get_details+0xdc>
cmp    $0x1,%r12d
jne    126b <exeknow_get_details+0xfb>
mov    0x0(%r13),%edi
lea    0xe50(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1090 <exeknow_get_details_mz@plt>
jmp    1283 <exeknow_get_details+0x113>
mov    0x0(%r13),%edi
lea    0xe3a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1050 <exeknow_get_details_e32@plt>
jmp    1283 <exeknow_get_details+0x113>
mov    0x0(%r13),%edi
lea    0xe19(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r15,%rdi
call   1030 <exeknow_get_details_elf@plt>
jmp    1283 <exeknow_get_details+0x113>
mov    0x0(%r13),%edi
lea    0xe04(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xfffffffc,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@stdout = global i32 0
@.str = [41 x i8] c"------------\0AFile Details:\0A------------\0A\00"
@.str.1 = [21 x i8] c"Executable Name: %s\0A\00"
@.str.2 = [28 x i8] c"Executable Size: %ld bytes\0A\00"
@.str.3 = [18 x i8] c"Executable Type: \00"
@.str.4 = [4 x i8] c"MZ\0A\00"
@.str.5 = [5 x i8] c"ELF\0A\00"
@.str.6 = [5 x i8] c"E32\0A\00"
@.str.7 = [9 x i8] c"Unknown\0A\00"
define i32 @exeknow_get_details(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %7
%8 = load i32*, i32** %4
%9 = load i32, i32* @SEEK_END
%10 = call i32 @fseek(i32* %8, i64 0, i32 %9)
%11 = load i32, i32* @stdout
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stdout
%14 = load i8*, i8** %6
%15 = call i8* @exeknow_getfilename(i8* %14)
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @stdout
%18 = load i32*, i32** %4
%19 = call i32 @ftell(i32* %18)
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @stdout
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* %5
switch i32 %23, label %39 [
i32 1, label %24
i32 2, label %29
i32 3, label %34
]
24: ; preds = %3
%25 = load i32, i32* @stdout
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32*, i32** %4
%28 = call i32 @exeknow_get_details_mz(i32* %27)
br label %42
29: ; preds = %3
%30 = load i32, i32* @stdout
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%32 = load i32*, i32** %4
%33 = call i32 @exeknow_get_details_elf(i32* %32)
br label %42
34: ; preds = %3
%35 = load i32, i32* @stdout
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%37 = load i32*, i32** %4
%38 = call i32 @exeknow_get_details_e32(i32* %37)
br label %42
39: ; preds = %3
%40 = load i32, i32* @stdout
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
store i32 -4, i32* %7
br label %42
42: ; preds = %39, %34, %29, %24
%43 = load i32, i32* %7
ret i32 %43
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@stdout = global i32 0
@.str = [41 x i8] c"------------\0AFile Details:\0A------------\0A\00"
@.str.1 = [21 x i8] c"Executable Name: %s\0A\00"
@.str.2 = [28 x i8] c"Executable Size: %ld bytes\0A\00"
@.str.3 = [18 x i8] c"Executable Type: \00"
@.str.4 = [4 x i8] c"MZ\0A\00"
@.str.5 = [5 x i8] c"ELF\0A\00"
@.str.6 = [5 x i8] c"E32\0A\00"
@.str.7 = [9 x i8] c"Unknown\0A\00"
define i32 @exeknow_get_details(i32* %0, i32 %1, i8* %2) {
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @fseek(i32* %0, i64 0, i32 %4)
%6 = load i32, i32* @stdout
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stdout
%9 = tail call i8* @exeknow_getfilename(i8* %2)
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @stdout
%12 = tail call i32 @ftell(i32* %0)
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @stdout
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
switch i32 %1, label %28 [
i32 1, label %16
i32 2, label %20
i32 3, label %24
]
16: ; preds = %3
%17 = load i32, i32* @stdout
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%19 = tail call i32 @exeknow_get_details_mz(i32* %0)
br label %31
20: ; preds = %3
%21 = load i32, i32* @stdout
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%23 = tail call i32 @exeknow_get_details_elf(i32* %0)
br label %31
24: ; preds = %3
%25 = load i32, i32* @stdout
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%27 = tail call i32 @exeknow_get_details_e32(i32* %0)
br label %31
28: ; preds = %3
%29 = load i32, i32* @stdout
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %31
31: ; preds = %28, %24, %20, %16
%32 = phi i32 [ -4, %28 ], [ 0, %24 ], [ 0, %20 ], [ 0, %16 ]
ret i32 %32
}