#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_SYNC;
int O_WRONLY;
int atoi(char *);
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ mkdir(char *, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int oflag = O_CREAT;
  if (strcmp(argv[1], "y") == 0)
    oflag |= O_SYNC;
  int partsize = atoi(argv[2]);
  int src_fd = open("2M.text", oflag);
  int dest_fd;
  int index = 1;
  char dst_name[10];
  char buf[partsize];
  int respone;
  mkdir("tmp", 0700);
  chdir("tmp");
  while ((respone = read(src_fd, buf, partsize)) > 0) {
    sprintf(dst_name, "%d", index);
    dest_fd = open(dst_name, O_CREAT | O_WRONLY);
    write(dest_fd, buf, respone);
    close(dest_fd);
    ++index;
  }
  if (respone == -1) {
    perror("2M.text");
    exit(EXIT_FAILURE);
  }
  close(src_fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1f(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11ff <main+0x4f>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    0xde9(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
lea    0xdb5(%rip),%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
lea    0xda4(%rip),%rdi
call   1050 <chdir@plt>
mov    -0x50(%rbp),%rsi
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
jle    12dc <main+0x12c>
lea    -0x2e(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd7a(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x2e(%rbp),%rdi
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
mov    0x2d0b(%rip),%rax
or     (%rax),%esi
call   1090 <open@plt>
mov    -0x50(%rbp),%rsi
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x44(%rbp),%edx
call   1040 <write@plt>
mov    -0x20(%rbp),%edi
call   1060 <close@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    126b <main+0xbb>
cmpl   $0xffffffff,-0x44(%rbp)
jne    1300 <main+0x150>
lea    0xd15(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    0x2e2d(%rip),%rax
mov    (%rax),%r15d
mov    0x8(%rsi),%rdi
lea    0xe27(%rip),%rsi
call   1080 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    11ee <main+0x3e>
mov    0x2df4(%rip),%rax
mov    (%rax),%ebx
or     %r15d,%ebx
mov    0x10(%r14),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r14d
lea    0xdfe(%rip),%rdi
mov    %ebx,%esi
call   1090 <open@plt>
mov    %eax,%r15d
mov    %rsp,-0x38(%rbp)
mov    %r14d,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xddd(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
mov    %rbx,%rdi
mov    %r14d,%ebx
call   1050 <chdir@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %r14d,%edx
call   1070 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    12d5 <main+0x125>
mov    %ebx,-0x2c(%rbp)
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x42(%rbp),%r13
mov    %r13,%rdi
lea    0xd90(%rip),%rsi
mov    %ebx,%edx
call   10c0 <sprintf@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
mov    0x2d63(%rip),%rax
or     (%rax),%esi
mov    %r13,%rdi
call   1090 <open@plt>
mov    %r15d,%r13d
mov    %eax,%r15d
mov    %eax,%edi
mov    %r12,%rsi
mov    %r14d,%edx
call   1040 <write@plt>
mov    %r15d,%edi
mov    %r13d,%r15d
call   1060 <close@plt>
add    $0x1,%ebx
mov    %r13d,%edi
mov    %r12,%rsi
mov    -0x2c(%rbp),%edx
call   1070 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
jg     1270 <main+0xc0>
cmp    $0xffffffff,%r14d
je     12ff <main+0x14f>
mov    %r15d,%edi
call   1060 <close@plt>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcfc(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@O_CREAT = global i32 0
@.str = [2 x i8] c"y\00"
@O_SYNC = global i32 0
@.str.1 = [8 x i8] c"2M.text\00"
@.str.2 = [4 x i8] c"tmp\00"
@.str.3 = [3 x i8] c"%d\00"
@O_WRONLY = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [10 x i8]
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @O_CREAT
store i32 %15, i32* %6
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %2
%22 = load i32, i32* @O_SYNC
%23 = load i32, i32* %6
%24 = or i32 %23, %22
store i32 %24, i32* %6
br label %25
25: ; preds = %21, %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %7
%30 = load i32, i32* %6
%31 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %30)
store i32 %31, i32* %8
store i32 1, i32* %10
%32 = load i32, i32* %7
%33 = zext i32 %32 to i64
%34 = call i8* @llvm.stacksave()
store i8* %34, i8** %12
%35 = alloca i8, i64 %33
store i64 %33, i64* %13
%36 = call i32 @mkdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 448)
%37 = call i32 @chdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %43, %25
%39 = load i32, i32* %8
%40 = load i32, i32* %7
%41 = call i32 @read(i32 %39, i8* %35, i32 %40)
store i32 %41, i32* %14
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %59
43: ; preds = %38
%44 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%45 = load i32, i32* %10
%46 = call i32 @sprintf(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%48 = load i32, i32* @O_CREAT
%49 = load i32, i32* @O_WRONLY
%50 = or i32 %48, %49
%51 = call i32 @open(i8* %47, i32 %50)
store i32 %51, i32* %9
%52 = load i32, i32* %9
%53 = load i32, i32* %14
%54 = call i32 @write(i32 %52, i8* %35, i32 %53)
%55 = load i32, i32* %9
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 1
store i32 %58, i32* %10
br label %38
59: ; preds = %38
%60 = load i32, i32* %14
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %66
62: ; preds = %59
%63 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %59
%67 = load i32, i32* %8
%68 = call i32 @close(i32 %67)
%69 = load i32, i32* @EXIT_SUCCESS
store i32 %69, i32* %3
%70 = load i8*, i8** %12
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@.str = [2 x i8] c"y\00"
@O_SYNC = global i32 0
@.str.1 = [8 x i8] c"2M.text\00"
@.str.2 = [4 x i8] c"tmp\00"
@.str.3 = [3 x i8] c"%d\00"
@O_WRONLY = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = load i32, i32* @O_CREAT
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = load i32, i32* @O_SYNC
%10 = select i1 %8, i32 %9, i32 0
%11 = or i32 %10, %4
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%17 = zext i32 %14 to i64
%18 = tail call i8* @llvm.stacksave()
%19 = alloca i8, i64 %17
%20 = tail call i32 @mkdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 448)
%21 = tail call i32 @chdir(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @read(i32 %15, i8* %19, i32 %14)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %37
24: ; preds = %2, %24
%25 = phi i32 [ %35, %24 ], [ %22, %2 ]
%26 = phi i32 [ %34, %24 ], [ 1, %2 ]
%27 = call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @O_CREAT
%29 = load i32, i32* @O_WRONLY
%30 = or i32 %29, %28
%31 = call i32 @open(i8* %16, i32 %30)
%32 = call i32 @write(i32 %31, i8* %19, i32 %25)
%33 = tail call i32 @close(i32 %31)
%34 = add nuw nsw i32 %26, 1
%35 = call i32 @read(i32 %15, i8* %19, i32 %14)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %24, label %37
37: ; preds = %24, %2
%38 = phi i32 [ %22, %2 ], [ %35, %24 ]
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = tail call i32 @exit(i32 %42)
unreachable
44: ; preds = %37
%45 = tail call i32 @close(i32 %15)
%46 = load i32, i32* @EXIT_SUCCESS
tail call void @llvm.stackrestore(i8* %18)
ret i32 %46
}