#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_SUCCESS;
int INT_MAX;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int splice(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/ *, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  char infile[128] = "./infile", outpipe[128] = "./outpipe";
  int rc, fd_in, fd_out, nbuf = INT_MAX;
  if (argc > 1)
    strcpy(infile, argv[1]);
  if (argc > 2)
    strcpy(outpipe, argv[2]);
  if (argc > 3)
    nbuf = atoi(argv[3]);
  printf("Input file: %s,  Output pipe: %s\n", infile, outpipe);
  fflush(NULL);
  if ((fd_in = open(infile, O_RDONLY)) < 0) {
    perror("open fd_in");
    exit(errno);
  };
  if ((fd_out = open(outpipe, O_WRONLY)) < 0) {
    perror("open fd_out");
    exit(errno);
  };
  do {
    if ((rc = splice(fd_in, NULL, fd_out, NULL, nbuf, 0)) < 0) {
      perror("splice");
      exit(errno);
    };
    printf("Transferred %8d bytes\n", rc);
  } while (rc > 0);
  close(fd_in);
  close(fd_out);
  printf("done\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe39(%rip),%rsi
mov    $0x80,%edx
call   1070 <memcpy@plt>
lea    -0x110(%rbp),%rdi
lea    0xea1(%rip),%rsi
mov    $0x80,%edx
call   1070 <memcpy@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x120(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1216 <main+0x76>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
cmpl   $0x2,-0x8(%rbp)
jle    1234 <main+0x94>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <strcpy@plt>
cmpl   $0x3,-0x8(%rbp)
jle    1251 <main+0xb1>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x120(%rbp)
lea    -0x90(%rbp),%rsi
lea    -0x110(%rbp),%rdx
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
lea    -0x90(%rbp),%rdi
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x118(%rbp)
cmp    $0x0,%eax
jge    12b4 <main+0x114>
lea    0xe81(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x110(%rbp),%rdi
mov    0x2cf6(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x11c(%rbp)
cmp    $0x0,%eax
jge    12f2 <main+0x152>
lea    0xe4e(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    12f7 <main+0x157>
mov    -0x118(%rbp),%edi
mov    -0x11c(%rbp),%edx
mov    -0x120(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%ecx
xor    %r9d,%r9d
mov    %rcx,%rsi
call   1030 <splice@plt>
mov    %eax,-0x114(%rbp)
cmp    $0x0,%eax
jge    1342 <main+0x1a2>
lea    0xe0a(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x114(%rbp),%esi
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x114(%rbp)
jg     12f7 <main+0x157>
mov    -0x118(%rbp),%edi
call   1060 <close@plt>
mov    -0x11c(%rbp),%edi
call   1060 <close@plt>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
movaps 0xe9b(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xe7c(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xe5d(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xe3e(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xe1f(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xe00(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xde1(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe8a(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe6e(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe52(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe36(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe1a(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xdfe(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    0x2d53(%rip),%rax
mov    (%rax),%r15d
cmp    $0x2,%edi
jl     12cd <main+0x12d>
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x8(%rsi),%rsi
lea    0x80(%rsp),%rdi
call   1040 <strcpy@plt>
cmp    $0x2,%ebp
je     12cd <main+0x12d>
mov    0x10(%r14),%rsi
mov    %rsp,%rdi
call   1040 <strcpy@plt>
cmp    $0x4,%ebp
jb     12cd <main+0x12d>
mov    0x18(%r14),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r15d
lea    0xe2c(%rip),%rdi
lea    0x80(%rsp),%rbx
mov    %rsp,%rdx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1080 <fflush@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
test   %eax,%eax
jns    1311 <main+0x171>
lea    0xe16(%rip),%rdi
jmp    139a <main+0x1fa>
mov    %eax,%r12d
mov    0x2c9d(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1090 <open@plt>
test   %eax,%eax
jns    1332 <main+0x192>
lea    0xdfd(%rip),%rdi
jmp    139a <main+0x1fa>
mov    %eax,%ebx
lea    0xe05(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
xor    %esi,%esi
mov    %ebx,%edx
xor    %ecx,%ecx
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1030 <splice@plt>
test   %eax,%eax
js     1393 <main+0x1f3>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebp,%ebp
jne    1340 <main+0x1a0>
mov    %r12d,%edi
call   1070 <close@plt>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xdd7(%rip),%rdi
call   1050 <puts@plt>
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xd9f(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c2a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@__const.main.infile = [128 x i8] c"./infile\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.outpipe = [128 x i8] c"./outpipe\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@INT_MAX = global i32 0
@.str = [34 x i8] c"Input file: %s, Output pipe: %s\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"open fd_in\00"
@errno = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [12 x i8] c"open fd_out\00"
@.str.3 = [7 x i8] c"splice\00"
@.str.4 = [23 x i8] c"Transferred %8d bytes\0A\00"
@.str.5 = [6 x i8] c"done\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca [128 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [128 x i8]* %6 to i8*
%13 = bitcast [128 x i8]* %7 to i8*
%14 = load i32, i32* @INT_MAX
store i32 %14, i32* %11
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strcpy(i8* %18, i8* %21)
br label %23
23: ; preds = %17, %2
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 2
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @strcpy(i8* %27, i8* %30)
br label %32
32: ; preds = %26, %23
%33 = load i32, i32* %4
%34 = icmp sgt i32 %33, 3
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 3
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %11
br label %40
40: ; preds = %35, %32
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %41, i8* %42)
%44 = call i32 @fflush(i32* null)
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%46 = load i32, i32* @O_RDONLY
%47 = call i32 @open(i8* %45, i32 %46)
store i32 %47, i32* %9
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %40
%50 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%51 = load i32, i32* @errno
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %40
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%55 = load i32, i32* @O_WRONLY
%56 = call i32 @open(i8* %54, i32 %55)
store i32 %56, i32* %10
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%60 = load i32, i32* @errno
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %53
br label %63
63: ; preds = %76, %62
%64 = load i32, i32* %9
%65 = load i32, i32* %10
%66 = load i32, i32* %11
%67 = call i32 @splice(i32 %64, i32* null, i32 %65, i32* null, i32 %66, i32 0)
store i32 %67, i32* %8
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %63
%70 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%71 = load i32, i32* @errno
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %63
%74 = load i32, i32* %8
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %73
%77 = load i32, i32* %8
%78 = icmp sgt i32 %77, 0
br i1 %78, label %63, label %79
79: ; preds = %76
%80 = load i32, i32* %9
%81 = call i32 @close(i32 %80)
%82 = load i32, i32* %10
%83 = call i32 @close(i32 %82)
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%85 = load i32, i32* @EXIT_SUCCESS
%86 = call i32 @exit(i32 %85)
unreachable
}

LLVM IR (-O2):
@__const.main.infile = [128 x i8] c"./infile\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.outpipe = [128 x i8] c"./outpipe\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@INT_MAX = global i32 0
@.str = [34 x i8] c"Input file: %s, Output pipe: %s\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"open fd_in\00"
@errno = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [12 x i8] c"open fd_out\00"
@.str.3 = [7 x i8] c"splice\00"
@.str.4 = [23 x i8] c"Transferred %8d bytes\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [5 x i8] c"done\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @INT_MAX
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %23
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @strcpy(i8* %5, i8* %11)
%13 = icmp eq i32 %0, 2
br i1 %13, label %23, label %14
14: ; preds = %9
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @strcpy(i8* %6, i8* %16)
%18 = icmp ugt i32 %0, 3
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
br label %23
23: ; preds = %2, %9, %19, %14
%24 = phi i32 [ %22, %19 ], [ %7, %14 ], [ %7, %9 ], [ %7, %2 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %6)
%26 = call i32 @fflush(i32* null)
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %5, i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %23
%31 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @errno
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %23
%35 = load i32, i32* @O_WRONLY
%36 = call i32 @open(i8* %6, i32 %35)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* @errno
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %34, %49
%43 = call i32 @splice(i32 %28, i32* null, i32 %36, i32* null, i32 %24, i32 0)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @errno
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %42
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%51 = icmp eq i32 %43, 0
br i1 %51, label %52, label %42
52: ; preds = %49
%53 = call i32 @close(i32 %28)
%54 = call i32 @close(i32 %36)
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%56 = load i32, i32* @EXIT_SUCCESS
%57 = call i32 @exit(i32 %56)
unreachable
}