#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 EXIT_FAILURE;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  FILE *fp_in;
  char *input_file = "image1.jpg";
  fp_in = fopen(input_file, "rb");
  if (fp_in == NULL) {
    perror("File opening failed");
    return EXIT_FAILURE;
  }
  fseek(fp_in, 0, SEEK_END);
  printf("File Size: %ld bytes\n", ftell(fp_in));
  printf("File Size in Kilo Byte: %ld\n", ftell(fp_in) / 1024);
  fclose(fp_in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b6 <main+0x56>
lea    0xe6e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1210 <main+0xb0>
mov    -0x10(%rbp),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,%esi
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11dc <main+0x7c>
mov    %rax,%rbx
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
lea    0xe80(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
lea    0x3ff(%rax),%esi
test   %eax,%eax
cmovns %eax,%esi
sar    $0xa,%esi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe2b(%rip),%rdi
call   1080 <perror@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%ebp
jmp    11d3 <main+0x73>

LLVM IR (-O0):
@.str = [11 x i8] c"image1.jpg\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"File opening failed\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@.str.3 = [22 x i8] c"File Size: %ld bytes\0A\00"
@.str.4 = [29 x i8] c"File Size in Kilo Byte: %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %3
%4 = load i8*, i8** %3
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
store i32 %10, i32* %1
br label %24
11: ; preds = %0
%12 = load i32*, i32** %2
%13 = load i32, i32* @SEEK_END
%14 = call i32 @fseek(i32* %12, i32 0, i32 %13)
%15 = load i32*, i32** %2
%16 = call i32 @ftell(i32* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = load i32*, i32** %2
%19 = call i32 @ftell(i32* %18)
%20 = sdiv i32 %19, 1024
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
store i32 0, i32* %1
br label %24
24: ; preds = %11, %8
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [11 x i8] c"image1.jpg\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"File opening failed\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@.str.3 = [22 x i8] c"File Size: %ld bytes\0A\00"
@.str.4 = [29 x i8] c"File Size in Kilo Byte: %ld\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%5 = load i32, i32* @EXIT_FAILURE
br label %15
6: ; preds = %0
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %1, i32 0, i32 %7)
%9 = tail call i32 @ftell(i32* %1)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = tail call i32 @ftell(i32* %1)
%12 = sdiv i32 %11, 1024
%13 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%14 = tail call i32 @fclose(i32* %1)
br label %15
15: ; preds = %6, %3
%16 = phi i32 [ %5, %3 ], [ 0, %6 ]
ret i32 %16
}