#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fork();
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
unsigned long fseek(int /*<<< orphan*/ *, unsigned long, int /*<<< orphan*/);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ usage(int, char **);
int main(int argc, char **argv) {
  usage(argc, argv);
  pid_t pid;
  FILE *fp1 = fopen(argv[1], "r");
  FILE *fp2 = fopen(argv[2], "w");
  int i;
  unsigned long len = fseek(fp1, 0L, SEEK_END);
  rewind(fp1);
  pid = fork();
  if (pid > 0) {
    for (i = 0; i < len / 2; i++)
      fputc(fgetc(fp1), fp2);
    fclose(fp1);
    fclose(fp2);
  } else if (pid == 0) {
    fseek(fp1, len / 2, SEEK_SET);
    fseek(fp2, len / 2, SEEK_SET);
    int c;
    while (1) {
      c = fgetc(fp1);
      if (c == EOF && feof(fp1))
        break;
      fputc(c, fp2);
    }
    fclose(fp1);
    fclose(fp2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1090 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe29(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <rewind@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    1270 <main+0xe0>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
mov    -0x38(%rbp),%rcx
shr    $0x1,%rcx
cmp    %rcx,%rax
jae    1259 <main+0xc9>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%edi
mov    -0x28(%rbp),%rsi
call   1060 <fputc@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1222 <main+0x92>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
jmp    130d <main+0x17d>
cmpq   $0x0,-0x18(%rbp)
jne    1308 <main+0x178>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
shr    $0x1,%rsi
mov    0x2d42(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
shr    $0x1,%rsi
mov    0x2d28(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2d1b(%rip),%rcx
cmp    (%rcx),%eax
jne    12e5 <main+0x155>
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     12e5 <main+0x155>
jmp    12f6 <main+0x166>
mov    -0x3c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <fputc@plt>
jmp    12af <main+0x11f>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
jmp    130d <main+0x17d>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1090 <usage@plt>
mov    0x8(%rbx),%rdi
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe44(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <rewind@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
jle    121a <main+0x8a>
cmp    $0x2,%rbx
jb     1277 <main+0xe7>
shr    %rbx
nopl   (%rax)
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
add    $0xffffffffffffffff,%rbx
jne    1200 <main+0x70>
jmp    1277 <main+0xe7>
jne    1287 <main+0xf7>
shr    %rbx
mov    0x2daa(%rip),%r12
mov    (%r12),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <fseek@plt>
mov    (%r12),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <fseek@plt>
mov    0x2d95(%rip),%r12
jmp    125a <main+0xca>
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
cmp    (%r12),%eax
jne    1250 <main+0xc0>
mov    %r15,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     1250 <main+0xc0>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @usage(i32 %12, i8** %13)
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %8
%23 = load i32*, i32** %7
%24 = load i32, i32* @SEEK_END
%25 = call i64 @fseek(i32* %23, i64 0, i32 %24)
store i64 %25, i64* %10
%26 = load i32*, i32** %7
%27 = call i32 @rewind(i32* %26)
%28 = call i64 (...) @fork()
store i64 %28, i64* %6
%29 = load i64, i64* %6
%30 = icmp sgt i64 %29, 0
br i1 %30, label %31, label %51
31: ; preds = %2
store i32 0, i32* %9
br label %32
32: ; preds = %43, %31
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = load i64, i64* %10
%36 = udiv i64 %35, 2
%37 = icmp ult i64 %34, %36
br i1 %37, label %38, label %46
38: ; preds = %32
%39 = load i32*, i32** %7
%40 = call i32 @fgetc(i32* %39)
%41 = load i32*, i32** %8
%42 = call i32 @fputc(i32 %40, i32* %41)
br label %43
43: ; preds = %38
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %32
46: ; preds = %32
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
%49 = load i32*, i32** %8
%50 = call i32 @fclose(i32* %49)
br label %86
51: ; preds = %2
%52 = load i64, i64* %6
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %85
54: ; preds = %51
%55 = load i32*, i32** %7
%56 = load i64, i64* %10
%57 = udiv i64 %56, 2
%58 = load i32, i32* @SEEK_SET
%59 = call i64 @fseek(i32* %55, i64 %57, i32 %58)
%60 = load i32*, i32** %8
%61 = load i64, i64* %10
%62 = udiv i64 %61, 2
%63 = load i32, i32* @SEEK_SET
%64 = call i64 @fseek(i32* %60, i64 %62, i32 %63)
br label %65
65: ; preds = %54, %76
%66 = load i32*, i32** %7
%67 = call i32 @fgetc(i32* %66)
store i32 %67, i32* %11
%68 = load i32, i32* %11
%69 = load i32, i32* @EOF
%70 = icmp eq i32 %68, %69
br i1 %70, label %71, label %76
71: ; preds = %65
%72 = load i32*, i32** %7
%73 = call i64 @feof(i32* %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %76
75: ; preds = %71
br label %80
76: ; preds = %71, %65
%77 = load i32, i32* %11
%78 = load i32*, i32** %8
%79 = call i32 @fputc(i32 %77, i32* %78)
br label %65
80: ; preds = %75
%81 = load i32*, i32** %7
%82 = call i32 @fclose(i32* %81)
%83 = load i32*, i32** %8
%84 = call i32 @fclose(i32* %83)
br label %85
85: ; preds = %80, %51
br label %86
86: ; preds = %85, %46
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @usage(i32 %0, i8** %1)
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @SEEK_END
%11 = tail call i64 @fseek(i32* %6, i64 0, i32 %10)
%12 = tail call i32 @rewind(i32* %6)
%13 = tail call i64 (...) @fork()
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %2
%16 = icmp ult i64 %11, 2
br i1 %16, label %42, label %17
17: ; preds = %15
%18 = lshr i64 %11, 1
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %23, %19 ]
%21 = tail call i32 @fgetc(i32* %6)
%22 = tail call i32 @fputc(i32 %21, i32* %9)
%23 = add nuw nsw i64 %20, 1
%24 = icmp eq i64 %23, %18
br i1 %24, label %42, label %19
25: ; preds = %2
%26 = icmp eq i64 %13, 0
br i1 %26, label %27, label %45
27: ; preds = %25
%28 = lshr i64 %11, 1
%29 = load i32, i32* @SEEK_SET
%30 = tail call i64 @fseek(i32* %6, i64 %28, i32 %29)
%31 = load i32, i32* @SEEK_SET
%32 = tail call i64 @fseek(i32* %9, i64 %28, i32 %31)
br label %33
33: ; preds = %40, %27
%34 = tail call i32 @fgetc(i32* %6)
%35 = load i32, i32* @EOF
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = tail call i64 @feof(i32* %6)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37, %33
%41 = tail call i32 @fputc(i32 %34, i32* %9)
br label %33
42: ; preds = %37, %19, %15
%43 = tail call i32 @fclose(i32* %6)
%44 = tail call i32 @fclose(i32* %9)
br label %45
45: ; preds = %42, %25
ret i32 0
}