#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 mode_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int close(int);
int creat(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int i, j, k, l;
  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
  char buf[4096];
  if (argc > 2) {
    if ((i = open(argv[1], O_RDONLY)) != -1) {
      if ((j = creat(argv[2], mode)) != -1) {
        while ((k = read(i, buf, 4096)) > 0 && l != -1) {
          l = write(j, buf, k);
        }
        if (k == -1) {
          perror("read");
          exit(1);
        } else if (l == -1) {
          perror("write");
          exit(1);
        }
        l = close(j);
        if (l == -1) {
          fprintf(stderr, "Kopie:");
          perror("close");
          exit(1);
        }
      } else {
        perror("creat");
        exit(1);
      }
      l = close(i);
      if (l == -1) {
        fprintf(stderr, "Zu kopierendes File:");
        perror("close");
        exit(1);
      }
    } else {
      perror("open");
      exit(1);
    }
  } else {
    fprintf(stderr, "Too few parameters for application %s\n", argv[0]);
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    0x2e37(%rip),%rcx
or     (%rcx),%eax
mov    0x2e16(%rip),%rcx
or     (%rcx),%eax
mov    0x2e05(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1375 <main+0x1f5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     135a <main+0x1da>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x24(%rbp),%esi
call   1090 <creat@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     12fd <main+0x17d>
jmp    120d <main+0x8d>
mov    -0x14(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1031(%rbp)
jle    1244 <main+0xc4>
cmpl   $0xffffffff,-0x20(%rbp)
setne  %al
mov    %al,-0x1031(%rbp)
mov    -0x1031(%rbp),%al
test   $0x1,%al
jne    1257 <main+0xd7>
jmp    1271 <main+0xf1>
mov    -0x18(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
jmp    120d <main+0x8d>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1291 <main+0x111>
lea    0xd7e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0xffffffff,-0x20(%rbp)
jne    12b1 <main+0x131>
lea    0xd63(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12b6 <main+0x136>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    12f8 <main+0x178>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
lea    0xd30(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    0xd29(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1313 <main+0x193>
lea    0xd14(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1355 <main+0x1d5>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    0xccc(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1370 <main+0x1f0>
lea    0xcd2(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    139d <main+0x21d>
mov    0x2c54(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xcac(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jl     1210 <main+0xa0>
mov    0x2e2a(%rip),%rax
mov    0x2e4b(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    0x2e28(%rip),%rax
or     (%rax),%ebp
mov    0x2e17(%rip),%rax
or     (%rax),%ebp
mov    0x8(%r14),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1234 <main+0xc4>
mov    %eax,%ebx
mov    0x10(%r14),%rdi
mov    %ebp,%esi
call   1080 <creat@plt>
cmp    $0xffffffff,%eax
je     123d <main+0xcd>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x1000,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     1246 <main+0xd6>
mov    %ebp,%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
je     124f <main+0xdf>
mov    %ebx,%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
je     1261 <main+0xf1>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe0f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdf2(%rip),%rdi
jmp    127f <main+0x10f>
lea    0xdce(%rip),%rdi
jmp    127f <main+0x10f>
lea    0xdb3(%rip),%rdi
jmp    127f <main+0x10f>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
jmp    1271 <main+0x101>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xd8d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@O_RDONLY = global i32 0
@.str = [5 x i8] c"read\00"
@.str.1 = [6 x i8] c"write\00"
@stderr = global i32 0
@.str.2 = [7 x i8] c"Kopie:\00"
@.str.3 = [6 x i8] c"close\00"
@.str.4 = [6 x i8] c"creat\00"
@.str.5 = [21 x i8] c"Zu kopierendes File:\00"
@.str.6 = [5 x i8] c"open\00"
@.str.7 = [39 x i8] c"Too few parameters for application %s\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IRGRP
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IROTH
%18 = or i32 %16, %17
store i32 %18, i32* %10
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 2
br i1 %20, label %21, label %93
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %6
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %89
28: ; preds = %21
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = load i32, i32* %10
%33 = call i32 @creat(i8* %31, i32 %32)
store i32 %33, i32* %7
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %75
35: ; preds = %28
br label %36
36: ; preds = %46, %35
%37 = load i32, i32* %6
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 4096)
store i32 %39, i32* %8
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* %9
%43 = icmp ne i32 %42, -1
br label %44
44: ; preds = %41, %36
%45 = phi i1 [ false, %36 ], [ %43, %41 ]
br i1 %45, label %46, label %51
46: ; preds = %44
%47 = load i32, i32* %7
%48 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%49 = load i32, i32* %8
%50 = call i32 @write(i32 %47, i8* %48, i32 %49)
store i32 %50, i32* %9
br label %36
51: ; preds = %44
%52 = load i32, i32* %8
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %51
%58 = load i32, i32* %9
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %57
br label %64
64: ; preds = %63
%65 = load i32, i32* %7
%66 = call i32 @close(i32 %65)
store i32 %66, i32* %9
%67 = load i32, i32* %9
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %74
69: ; preds = %64
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%72 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %64
br label %78
75: ; preds = %28
%76 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %74
%79 = load i32, i32* %6
%80 = call i32 @close(i32 %79)
store i32 %80, i32* %9
%81 = load i32, i32* %9
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %88
83: ; preds = %78
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%86 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %78
br label %92
89: ; preds = %21
%90 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %88
br label %100
93: ; preds = %2
%94 = load i32, i32* @stderr
%95 = load i8**, i8*** %5
%96 = getelementptr inbounds i8*, i8** %95, i64 0
%97 = load i8*, i8** %96
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %97)
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %92
ret i32 0
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@O_RDONLY = global i32 0
@.str = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.2 = [7 x i8] c"Kopie:\00"
@.str.3 = [6 x i8] c"close\00"
@.str.4 = [6 x i8] c"creat\00"
@.str.5 = [21 x i8] c"Zu kopierendes File:\00"
@.str.6 = [5 x i8] c"open\00"
@.str.7 = [39 x i8] c"Too few parameters for application %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %5, %4
%7 = load i32, i32* @S_IRGRP
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IROTH
%10 = or i32 %8, %9
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%12 = icmp sgt i32 %0, 2
br i1 %12, label %13, label %52
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 @open(i8* %15, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %49, label %19
19: ; preds = %13
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @creat(i8* %21, i32 %10)
%23 = icmp eq i32 %22, -1
br i1 %23, label %38, label %24
24: ; preds = %19
%25 = call i32 @read(i32 %17, i8* %11, i32 4096)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %24
%31 = tail call i32 @close(i32 %22)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%36 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %19
%39 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %30
%42 = tail call i32 @close(i32 %17)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %57
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%47 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%48 = tail call i32 @exit(i32 1)
unreachable
49: ; preds = %13
%50 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%51 = tail call i32 @exit(i32 1)
unreachable
52: ; preds = %2
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %1
%55 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %54)
%56 = tail call i32 @exit(i32 1)
unreachable
57: ; preds = %41
ret i32 0
}