#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 */
struct stat {
  size_t st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int fileno(int /*<<< orphan*/ *);
int fstat(int, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
unsigned long getfilelen(FILE *file, size_t size) {
  int filenum, rt;
  struct stat buf;
  filenum = fileno(file);
  rt = fstat(filenum, &buf);
  if (rt == -1) {
    perror("\nError in getfilelen()");
    printf("\n");
    exit(-1);
  }
  return (unsigned long)(buf.st_size / size);
}


x86 assembly (clang, -O0):
<getfilelen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1070 <fstat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11a7 <getfilelen+0x57>
lea    0xe74(%rip),%rdi
call   1050 <perror@plt>
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfilelen>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
call   1040 <fileno@plt>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1070 <fstat@plt>
cmp    $0xffffffff,%eax
je     1190 <getfilelen+0x40>
mov    0x8(%rsp),%rax
mov    %rax,%rcx
or     %rbx,%rcx
shr    $0x20,%rcx
je     1186 <getfilelen+0x36>
xor    %edx,%edx
div    %rbx
jmp    118a <getfilelen+0x3a>
xor    %edx,%edx
div    %ebx
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe69(%rip),%rdi
call   1050 <perror@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [23 x i8] c"\0AError in getfilelen()\00"
@.str.1 = [2 x i8] c"\0A\00"
define i64 @getfilelen(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
store i32* %0, i32** %3
store i64 %1, i64* %4
%8 = load i32*, i32** %3
%9 = call i32 @fileno(i32* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = call i32 @fstat(i32 %10, %struct.stat* %7)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%20 = load i64, i64* %19
%21 = load i64, i64* %4
%22 = udiv i64 %20, %21
ret i64 %22
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [23 x i8] c"\0AError in getfilelen()\00"
define i64 @getfilelen(i32* nocapture %0, i64 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i32 @fileno(i32* %0)
%6 = call i32 @fstat(i32 %5, %struct.stat* %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @putchar(i32 10)
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%14 = load i64, i64* %13
%15 = udiv i64 %14, %1
ret i64 %15
}