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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ S_IWRITE;
int /*<<< orphan*/ close(int);
int creat(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd1, fd2;
  char buf[256];
  int read_size = 256;
  int total_write_byte = 0;
  if (argc != 3) {
    printf("%s <filename1> <filename2>\n", argv[0]);
    exit(1);
  }
  fd1 = open(argv[1], O_RDONLY);
  if (fd1 < 0) {
    printf("could not open %s\n", argv[1]);
    exit(1);
  }
  fd2 = creat(argv[2], S_IWRITE);
  if (fd2 < 0) {
    printf("could not open %s\n", argv[2]);
    exit(1);
  }
  while (read_size > 0) {
    read_size = read(fd1, buf, sizeof(buf));
    total_write_byte += write(fd2, buf, read_size);
  }
  printf(";; total write bytes to stdout%d\n", total_write_byte);
  close(fd1);
  close(fd2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x100,-0x124(%rbp)
movl   $0x0,-0x128(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11c6 <main+0x56>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1209 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
call   1080 <creat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    124c <main+0xdc>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1251 <main+0xe1>
cmpl   $0x0,-0x124(%rbp)
jle    12a5 <main+0x135>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,-0x124(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
call   1030 <write@plt>
mov    %rax,%rcx
movslq -0x128(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x128(%rbp)
jmp    1251 <main+0xe1>
mov    -0x128(%rbp),%esi
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    1227 <main+0xb7>
mov    0x8(%r14),%rdi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1233 <main+0xc3>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
call   1080 <creat@plt>
test   %eax,%eax
js     1239 <main+0xc9>
mov    %eax,%r12d
xor    %ebx,%ebx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,%ebp
mov    %r12d,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    %eax,%ebx
test   %ebp,%ebp
jg     11d0 <main+0x60>
lea    0xe33(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %r12d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rsi
lea    0xdcf(%rip),%rdi
jmp    1244 <main+0xd4>
mov    0x8(%r14),%rsi
jmp    123d <main+0xcd>
mov    0x10(%r14),%rsi
lea    0xdd8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"%s <filename1> <filename2>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"could not open %s\0A\00"
@S_IWRITE = global i32 0
@.str.2 = [34 x i8] c";; total write bytes to stdout%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 256, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %19
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = load i32, i32* @S_IWRITE
%38 = call i32 @creat(i8* %36, i32 %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %33
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %33
br label %48
48: ; preds = %51, %47
%49 = load i32, i32* %9
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %63
51: ; preds = %48
%52 = load i32, i32* %6
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%54 = call i32 @read(i32 %52, i8* %53, i32 256)
store i32 %54, i32* %9
%55 = load i32, i32* %7
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%57 = load i32, i32* %9
%58 = call i64 @write(i32 %55, i8* %56, i32 %57)
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = add nsw i64 %60, %58
%62 = trunc i64 %61 to i32
store i32 %62, i32* %10
br label %48
63: ; preds = %48
%64 = load i32, i32* %10
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %64)
%66 = load i32, i32* %6
%67 = call i32 @close(i32 %66)
%68 = load i32, i32* %7
%69 = call i32 @close(i32 %68)
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str = [28 x i8] c"%s <filename1> <filename2>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"could not open %s\0A\00"
@S_IWRITE = global i32 0
@.str.2 = [34 x i8] c";; total write bytes to stdout%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i8*, i8** %11
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %10
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @S_IWRITE
%24 = tail call i32 @creat(i8* %22, i32 %23)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i8*, i8** %21
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %20, %30
%31 = phi i32 [ %35, %30 ], [ 0, %20 ]
%32 = call i32 @read(i32 %14, i8* %4, i32 256)
%33 = call i64 @write(i32 %24, i8* %4, i32 %32)
%34 = trunc i64 %33 to i32
%35 = add i32 %31, %34
%36 = icmp sgt i32 %32, 0
br i1 %36, label %30, label %37
37: ; preds = %30
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%39 = tail call i32 @close(i32 %14)
%40 = tail call i32 @close(i32 %24)
ret i32 0
}