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

/* Variables and functions */
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
size_t getpagesize();
int read(int /*<<< orphan*/, int /*<<< orphan*/ *, size_t);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  signal(SIGTERM, SIG_IGN);
  size_t chunk_size = getpagesize();
  uint8_t buffer[chunk_size];
  ssize_t bytes, total = 0;
  char tick = '.';
  FILE *fh = fopen("/tmp/xfer-sink.dat", "w+");
  for (;;) {
    bytes = read(0, buffer, chunk_size);
    if (bytes == 0) {
      break;
    } else if (bytes == -1) {
      break;
    }
    total += bytes;
    fwrite(buffer, 1, bytes, fh);
    fflush(fh);
  }
  fclose(fh);
  exit(0);
}


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    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
xor    %eax,%eax
call   1080 <getpagesize@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
movb   $0x2e,-0x31(%rbp)
lea    0xe0e(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %edi,%edi
call   1040 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1223 <main+0xa3>
jmp    1263 <main+0xe3>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1232 <main+0xb2>
jmp    1263 <main+0xe3>
jmp    1237 <main+0xb7>
mov    -0x48(%rbp),%rdi
mov    -0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    -0x40(%rbp),%rdi
call   1060 <fflush@plt>
jmp    1202 <main+0x82>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
xor    %eax,%eax
call   1080 <getpagesize@plt>
mov    %rax,%r14
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe39(%rip),%rdi
lea    0xe45(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <read@plt>
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jb     1221 <main+0xa1>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
xor    %edi,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <read@plt>
mov    %eax,%ecx
add    $0x1,%ecx
cmp    $0x1,%ecx
ja     11f0 <main+0x70>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@SIGTERM = global i32 0
@SIG_IGN = global i32 0
@.str = [19 x i8] c"/tmp/xfer-sink.dat\00"
@.str.1 = [3 x i8] c"w+\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @SIGTERM
%14 = load i32, i32* @SIG_IGN
%15 = call i32 @signal(i32 %13, i32 %14)
%16 = call i64 (...) @getpagesize()
store i64 %16, i64* %6
%17 = load i64, i64* %6
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %7
%19 = alloca i32, i64 %17
store i64 %17, i64* %8
store i32 0, i32* %10
store i8 46, i8* %11
%20 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %12
br label %21
21: ; preds = %32, %2
%22 = load i64, i64* %6
%23 = call i32 @read(i32 0, i32* %19, i64 %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
br label %41
27: ; preds = %21
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %31
30: ; preds = %27
br label %41
31: ; preds = %27
br label %32
32: ; preds = %31
%33 = load i32, i32* %9
%34 = load i32, i32* %10
%35 = add nsw i32 %34, %33
store i32 %35, i32* %10
%36 = load i32, i32* %9
%37 = load i32*, i32** %12
%38 = call i32 @fwrite(i32* %19, i32 1, i32 %36, i32* %37)
%39 = load i32*, i32** %12
%40 = call i32 @fflush(i32* %39)
br label %21
41: ; preds = %30, %26
%42 = load i32*, i32** %12
%43 = call i32 @fclose(i32* %42)
%44 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@SIGTERM = global i32 0
@SIG_IGN = global i32 0
@.str = [19 x i8] c"/tmp/xfer-sink.dat\00"
@.str.1 = [3 x i8] c"w+\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @SIGTERM
%4 = load i32, i32* @SIG_IGN
%5 = tail call i32 @signal(i32 %3, i32 %4)
%6 = tail call i64 (...) @getpagesize()
%7 = alloca i32, i64 %6
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @read(i32 0, i32* %7, i64 %6)
%10 = add i32 %9, 1
%11 = icmp ult i32 %10, 2
br i1 %11, label %19, label %12
12: ; preds = %2, %12
%13 = phi i32 [ %16, %12 ], [ %9, %2 ]
%14 = call i32 @fwrite(i32* %7, i32 1, i32 %13, i32* %8)
%15 = tail call i32 @fflush(i32* %8)
%16 = call i32 @read(i32 0, i32* %7, i64 %6)
%17 = add i32 %16, 1
%18 = icmp ult i32 %17, 2
br i1 %18, label %19, label %12
19: ; preds = %12, %2
%20 = tail call i32 @fclose(i32* %8)
%21 = tail call i32 @exit(i32 0)
unreachable
}