#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*/ F_OK;
int /*<<< orphan*/ SEEK_END;
int access(char *, int /*<<< orphan*/);
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*/ printf(char *, char *);
int computePartitionSize(char *file, int howMany, int firstFlag) {
  if (access(file, F_OK) == -1) {
    printf("%s\n", "File does not exist");
    return -1;
  }
  FILE *fp = fopen(file, "r");
  fseek(fp, 0, SEEK_END);
  int totalSize = ftell(fp);
  fclose(fp);
  if (firstFlag) {
    return ((totalSize / howMany) + (totalSize % howMany));
  }
  return totalSize / howMany;
}


x86 assembly (clang, -O0):
<computePartitionSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
jne    11ac <computePartitionSize+0x4c>
lea    0xe6c(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121b <computePartitionSize+0xbb>
mov    -0x10(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x18(%rbp)
je     1211 <computePartitionSize+0xb1>
mov    -0x24(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    -0x28(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x4(%rbp)
jmp    121b <computePartitionSize+0xbb>
mov    -0x24(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computePartitionSize>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     11c9 <computePartitionSize+0x69>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
cltd
idiv   %r15d
test   %r14d,%r14d
je     11e1 <computePartitionSize+0x81>
add    %edx,%eax
jmp    11e1 <computePartitionSize+0x81>
lea    0xe30(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [20 x i8] c"File does not exist\00"
@.str.2 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i32 @computePartitionSize(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i32, i32* @F_OK
%12 = call i32 @access(i8* %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %40
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %8
%19 = load i32*, i32** %8
%20 = load i32, i32* @SEEK_END
%21 = call i32 @fseek(i32* %19, i32 0, i32 %20)
%22 = load i32*, i32** %8
%23 = call i32 @ftell(i32* %22)
store i32 %23, i32* %9
%24 = load i32*, i32** %8
%25 = call i32 @fclose(i32* %24)
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %16
%29 = load i32, i32* %9
%30 = load i32, i32* %6
%31 = sdiv i32 %29, %30
%32 = load i32, i32* %9
%33 = load i32, i32* %6
%34 = srem i32 %32, %33
%35 = add nsw i32 %31, %34
store i32 %35, i32* %4
br label %40
36: ; preds = %16
%37 = load i32, i32* %9
%38 = load i32, i32* %6
%39 = sdiv i32 %37, %38
store i32 %39, i32* %4
br label %40
40: ; preds = %36, %28, %14
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [20 x i8] c"File does not exist\00"
@.str.2 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i32 @computePartitionSize(i8* nocapture %0, i32 %1, i32 %2) {
%4 = load i32, i32* @F_OK
%5 = tail call i32 @access(i8* %0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %20
9: ; preds = %3
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %10, i32 0, i32 %11)
%13 = tail call i32 @ftell(i32* %10)
%14 = tail call i32 @fclose(i32* %10)
%15 = icmp eq i32 %2, 0
%16 = sdiv i32 %13, %1
%17 = srem i32 %13, %1
br i1 %15, label %20, label %18
18: ; preds = %9
%19 = add nsw i32 %17, %16
br label %20
20: ; preds = %9, %18, %7
%21 = phi i32 [ -1, %7 ], [ %19, %18 ], [ %16, %9 ]
ret i32 %21
}