#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ kill(char const *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, size_t);
void slice(const char *sourceFile, const char *destinationFile, size_t parts) {
  FILE *srcFile = fopen(sourceFile, "r");
  if (!srcFile)
    kill(sourceFile);
  fseek(srcFile, 0, SEEK_END);
  long long position = ftell(srcFile);
  fseek(srcFile, 0, SEEK_SET);
  long long partSize = (position / parts) + 1;
  char buffer[4096];
  size_t i;
  for (i = 0; i < parts; i++) {
    char name[11];
    sprintf(name, "Part-%lu.jpg", i + 1);
    FILE *currentDestFile = fopen(name, "w");
    if (!currentDestFile)
      kill("Could not create a part");
    size_t writtenBytes = 0;
    while (writtenBytes <= partSize && !feof(srcFile)) {
      size_t readBytes = fread(buffer, 1, 4096, srcFile);
      fwrite(buffer, 1, readBytes, currentDestFile);
      writtenBytes += readBytes;
    }
    fclose(currentDestFile);
  }
  fclose(srcFile);
  printf("Done!");
}


x86 assembly (clang, -O0):
<slice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11df <slice+0x3f>
mov    -0x8(%rbp),%rdi
call   1080 <kill@plt>
mov    -0x20(%rbp),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x1038(%rbp)
mov    -0x1038(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1361 <slice+0x1c1>
lea    -0x1043(%rbp),%rdi
mov    -0x1038(%rbp),%rdx
add    $0x1,%rdx
lea    0xda5(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x1043(%rbp),%rdi
lea    0xd9f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x1050(%rbp)
cmpq   $0x0,-0x1050(%rbp)
jne    1296 <slice+0xf6>
lea    0xd80(%rip),%rdi
call   1080 <kill@plt>
movq   $0x0,-0x1058(%rbp)
mov    -0x1058(%rbp),%rcx
xor    %eax,%eax
cmp    -0x30(%rbp),%rcx
mov    %al,-0x1061(%rbp)
ja     12d1 <slice+0x131>
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1061(%rbp)
mov    -0x1061(%rbp),%al
test   $0x1,%al
jne    12e4 <slice+0x144>
jmp    133e <slice+0x19e>
lea    -0x1030(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,-0x1060(%rbp)
lea    -0x1030(%rbp),%rdi
mov    -0x1060(%rbp),%rdx
mov    -0x1050(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    -0x1060(%rbp),%rax
add    -0x1058(%rbp),%rax
mov    %rax,-0x1058(%rbp)
jmp    12a1 <slice+0x101>
mov    -0x1050(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1038(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1038(%rbp)
jmp    1233 <slice+0x93>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xcb8(%rip),%rdi
call   1050 <printf@plt>
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %rdx,%rbp
mov    %rdi,%r14
lea    0xe42(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11d3 <slice+0x33>
mov    %r14,%rdi
call   1080 <kill@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r14
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rax
or     %rbp,%rax
shr    $0x20,%rax
je     1225 <slice+0x85>
mov    %r14,%rax
xor    %edx,%edx
div    %rbp
mov    %rax,%r15
test   %rbp,%rbp
jne    1238 <slice+0x98>
jmp    12f4 <slice+0x154>
mov    %r14d,%eax
xor    %edx,%edx
div    %ebp
mov    %eax,%r15d
test   %rbp,%rbp
je     12f4 <slice+0x154>
add    $0x1,%r15
xor    %edx,%edx
lea    0x20(%rsp),%r13
mov    %rbp,(%rsp)
jmp    126a <slice+0xca>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rbp
mov    0x8(%rsp),%rdx
cmp    %rbp,%rdx
je     12f4 <slice+0x154>
add    $0x1,%rdx
lea    0x15(%rsp),%rbp
mov    %rbp,%rdi
lea    0xd85(%rip),%rsi
mov    %rdx,0x8(%rsp)
call   10b0 <sprintf@plt>
mov    %rbp,%rdi
lea    0xd7e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    12aa <slice+0x10a>
lea    0xd6c(%rip),%rdi
call   1080 <kill@plt>
xor    %r12d,%r12d
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1250 <slice+0xb0>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rax,%rbp
mov    %r13,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
add    %rbp,%r12
cmp    %r15,%r12
jbe    12b0 <slice+0x110>
jmp    1250 <slice+0xb0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xd26(%rip),%rdi
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [13 x i8] c"Part-%lu.jpg\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [24 x i8] c"Could not create a part\00"
@.str.4 = [6 x i8] c"Done!\00"
define void @slice(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca [4096 x i8]
%11 = alloca i64
%12 = alloca [11 x i8]
%13 = alloca i32*
%14 = alloca i64
%15 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%16 = load i8*, i8** %4
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = icmp ne i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %3
%21 = load i8*, i8** %4
%22 = call i32 @kill(i8* %21)
br label %23
23: ; preds = %20, %3
%24 = load i32*, i32** %7
%25 = load i32, i32* @SEEK_END
%26 = call i32 @fseek(i32* %24, i32 0, i32 %25)
%27 = load i32*, i32** %7
%28 = call i64 @ftell(i32* %27)
store i64 %28, i64* %8
%29 = load i32*, i32** %7
%30 = load i32, i32* @SEEK_SET
%31 = call i32 @fseek(i32* %29, i32 0, i32 %30)
%32 = load i64, i64* %8
%33 = load i64, i64* %6
%34 = udiv i64 %32, %33
%35 = add i64 %34, 1
store i64 %35, i64* %9
store i64 0, i64* %11
br label %36
36: ; preds = %77, %23
%37 = load i64, i64* %11
%38 = load i64, i64* %6
%39 = icmp ult i64 %37, %38
br i1 %39, label %40, label %80
40: ; preds = %36
%41 = getelementptr inbounds [11 x i8], [11 x i8]* %12, i64 0, i64 0
%42 = load i64, i64* %11
%43 = add i64 %42, 1
%44 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %43)
%45 = getelementptr inbounds [11 x i8], [11 x i8]* %12, i64 0, i64 0
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %46, i32** %13
%47 = load i32*, i32** %13
%48 = icmp ne i32* %47, null
br i1 %48, label %51, label %49
49: ; preds = %40
%50 = call i32 @kill(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %40
store i64 0, i64* %14
br label %52
52: ; preds = %63, %51
%53 = load i64, i64* %14
%54 = load i64, i64* %9
%55 = icmp ule i64 %53, %54
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = load i32*, i32** %7
%58 = call i32 @feof(i32* %57)
%59 = icmp ne i32 %58, 0
%60 = xor i1 %59, true
br label %61
61: ; preds = %56, %52
%62 = phi i1 [ false, %52 ], [ %60, %56 ]
br i1 %62, label %63, label %74
63: ; preds = %61
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%65 = load i32*, i32** %7
%66 = call i64 @fread(i8* %64, i32 1, i32 4096, i32* %65)
store i64 %66, i64* %15
%67 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%68 = load i64, i64* %15
%69 = load i32*, i32** %13
%70 = call i32 @fwrite(i8* %67, i32 1, i64 %68, i32* %69)
%71 = load i64, i64* %15
%72 = load i64, i64* %14
%73 = add i64 %72, %71
store i64 %73, i64* %14
br label %52
74: ; preds = %61
%75 = load i32*, i32** %13
%76 = call i32 @fclose(i32* %75)
br label %77
77: ; preds = %74
%78 = load i64, i64* %11
%79 = add i64 %78, 1
store i64 %79, i64* %11
br label %36
80: ; preds = %36
%81 = load i32*, i32** %7
%82 = call i32 @fclose(i32* %81)
%83 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [13 x i8] c"Part-%lu.jpg\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [24 x i8] c"Could not create a part\00"
@.str.4 = [6 x i8] c"Done!\00"
define void @slice(i8* %0, i8* nocapture readnone %1, i64 %2) {
%4 = alloca [4096 x i8]
%5 = alloca [11 x i8]
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @kill(i8* %0)
br label %10
10: ; preds = %8, %3
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %6, i32 0, i32 %11)
%13 = tail call i64 @ftell(i32* %6)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %6, i32 0, i32 %14)
%16 = udiv i64 %13, %2
%17 = add i64 %16, 1
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%19 = icmp eq i64 %2, 0
br i1 %19, label %43, label %20
20: ; preds = %10
%21 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
br label %22
22: ; preds = %20, %40
%23 = phi i64 [ 0, %20 ], [ %24, %40 ]
%24 = add nuw i64 %23, 1
%25 = call i32 @sprintf(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %24)
%26 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = tail call i32 @kill(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %22
br label %31
31: ; preds = %30, %35
%32 = phi i64 [ %38, %35 ], [ 0, %30 ]
%33 = tail call i32 @feof(i32* %6)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = call i64 @fread(i8* %18, i32 1, i32 4096, i32* %6)
%37 = call i32 @fwrite(i8* %18, i32 1, i64 %36, i32* %26)
%38 = add i64 %36, %32
%39 = icmp ugt i64 %38, %17
br i1 %39, label %40, label %31
40: ; preds = %35, %31
%41 = tail call i32 @fclose(i32* %26)
%42 = icmp eq i64 %24, %2
br i1 %42, label %43, label %22
43: ; preds = %40, %10
%44 = tail call i32 @fclose(i32* %6)
%45 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret void
}