#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ext_fail(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char getchar();
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ write(int, char *, int);
int main(int argc, char *argv[]) {
  int i = 0;
  struct stat s_s, s_d;
  int fd_s, fd_d;
  char buff[1024];
  if (argc != 3) {
    fprintf(stderr, "Syntax: auf2 Quelldatei Zieldatei\n");
    exit(1);
  }
  if (stat(argv[1], &s_s) != 0) {
    ext_fail("Quell", argv[1]);
  }
  if ((fd_s = open(argv[1], O_RDONLY)) < 0) {
    ext_fail("Quell", argv[1]);
  }
  if (stat(argv[2], &s_d) == 0) {
    printf("Datei '%s' existiert bereits .. überschreiben? (y/N) ", argv[2]);
    if (getchar() != 'y') {
      printf("Überschreibe NICHT!\nBeende..\n");
      exit(0);
    }
    printf("ÜBERSCHREIBE!\n");
  }
  if ((fd_d = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, s_s.st_mode)) < 0) {
    ext_fail("Ziel", argv[2]);
  }
  while ((i = read(fd_s, buff, 1024)) > 0) {
    if (write(fd_d, buff, i) < 0) {
      ext_fail("Ziel", argv[2]);
    }
  }
  close(fd_s);
  close(fd_d);
  if (i == 0) {
    printf("Datei '%s' erfolgreich nach '%s' kopiert\n", argv[1], argv[2]);
  } else {
    ext_fail("Quell", argv[1]);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11e9 <main+0x49>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
je     1218 <main+0x78>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe10(%rip),%rdi
call   1050 <ext_fail@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1250 <main+0xb0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdd8(%rip),%rdi
call   1050 <ext_fail@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
jne    12b7 <main+0x117>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
movsbl %al,%eax
cmp    $0x79,%eax
je     12a9 <main+0x109>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2cf2(%rip),%rax
mov    (%rax),%esi
mov    0x2d29(%rip),%rax
or     (%rax),%esi
mov    0x2d18(%rip),%rax
or     (%rax),%esi
mov    -0x18(%rbp),%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    1304 <main+0x164>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd90(%rip),%rdi
call   1050 <ext_fail@plt>
jmp    1309 <main+0x169>
mov    -0x24(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    135e <main+0x1be>
mov    -0x28(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    1359 <main+0x1b9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd3b(%rip),%rdi
call   1050 <ext_fail@plt>
jmp    1309 <main+0x169>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
mov    -0x28(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x14(%rbp)
jne    139b <main+0x1fb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13af <main+0x20f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xc79(%rip),%rdi
call   1050 <ext_fail@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
cmp    $0x3,%edi
jne    12f6 <main+0x146>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
call   10b0 <stat@plt>
test   %rax,%rax
je     11ee <main+0x3e>
mov    0x8(%r14),%rsi
lea    0xe3a(%rip),%rdi
call   1060 <ext_fail@plt>
mov    0x8(%r14),%rdi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10c0 <open@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    1219 <main+0x69>
mov    0x8(%r14),%rsi
lea    0xe0f(%rip),%rdi
call   1060 <ext_fail@plt>
mov    0x10(%r14),%rdi
lea    0x8(%rsp),%rsi
call   10b0 <stat@plt>
test   %rax,%rax
jne    1259 <main+0xa9>
mov    0x10(%r14),%rsi
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0x79,%al
jne    1359 <main+0x1a9>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%r14),%rdi
mov    0x2d54(%rip),%rax
mov    0x2d8d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d7a(%rip),%rax
or     (%rax),%esi
mov    (%rsp),%edx
xor    %eax,%eax
call   10c0 <open@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    1299 <main+0xe9>
mov    0x10(%r14),%rsi
lea    0xdcc(%rip),%rdi
call   1060 <ext_fail@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1315 <main+0x165>
lea    0x10(%rsp),%rbp
lea    0xda3(%rip),%r12
jmp    12d6 <main+0x126>
nop
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1315 <main+0x165>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    12c0 <main+0x110>
mov    0x10(%r14),%rsi
mov    %r12,%rdi
call   1060 <ext_fail@plt>
jmp    12c0 <main+0x110>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
lea    0xcfa(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    %r13d,%edi
call   1070 <close@plt>
mov    0x8(%r14),%rsi
test   %ebx,%ebx
jne    1346 <main+0x196>
mov    0x10(%r14),%rdx
lea    0xd2d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xcd6(%rip),%rdi
call   1060 <ext_fail@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
lea    0xd3e(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"Syntax: auf2 Quelldatei Zieldatei\0A\00"
@.str.1 = [6 x i8] c"Quell\00"
@O_RDONLY = global i32 0
@.str.2 = [55 x i8] c"Datei '%s' existiert bereits .. \C3\BCberschreiben? (y/N) \00"
@.str.3 = [31 x i8] c"\C3\9Cberschreibe NICHT!\0ABeende..\0A\00"
@.str.4 = [16 x i8] c"\C3\9CBERSCHREIBE!\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.5 = [5 x i8] c"Ziel\00"
@.str.6 = [42 x i8] c"Datei '%s' erfolgreich nach '%s' kopiert\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @stat(i8* %21, %struct.stat* %7)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @ext_fail(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %24, %18
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i32, i32* @O_RDONLY
%34 = call i32 (i8*, i32, ...) @open(i8* %32, i32 %33)
store i32 %34, i32* %9
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %29
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @ext_fail(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %36, %29
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = call i64 @stat(i8* %44, %struct.stat* %8)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %60
47: ; preds = %41
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %50)
%52 = call signext i8 (...) @getchar()
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 121
br i1 %54, label %55, label %58
55: ; preds = %47
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %47
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %58, %41
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 2
%63 = load i8*, i8** %62
%64 = load i32, i32* @O_WRONLY
%65 = load i32, i32* @O_CREAT
%66 = or i32 %64, %65
%67 = load i32, i32* @O_TRUNC
%68 = or i32 %66, %67
%69 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%70 = load i32, i32* %69
%71 = call i32 (i8*, i32, ...) @open(i8* %63, i32 %68, i32 %70)
store i32 %71, i32* %10
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %60
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 2
%76 = load i8*, i8** %75
%77 = call i32 @ext_fail(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %76)
br label %78
78: ; preds = %73, %60
br label %79
79: ; preds = %95, %78
%80 = load i32, i32* %9
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%82 = call i32 @read(i32 %80, i8* %81, i32 1024)
store i32 %82, i32* %6
%83 = icmp sgt i32 %82, 0
br i1 %83, label %84, label %96
84: ; preds = %79
%85 = load i32, i32* %10
%86 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%87 = load i32, i32* %6
%88 = call i64 @write(i32 %85, i8* %86, i32 %87)
%89 = icmp slt i64 %88, 0
br i1 %89, label %90, label %95
90: ; preds = %84
%91 = load i8**, i8*** %5
%92 = getelementptr inbounds i8*, i8** %91, i64 2
%93 = load i8*, i8** %92
%94 = call i32 @ext_fail(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %93)
br label %95
95: ; preds = %90, %84
br label %79
96: ; preds = %79
%97 = load i32, i32* %9
%98 = call i32 @close(i32 %97)
%99 = load i32, i32* %10
%100 = call i32 @close(i32 %99)
%101 = load i32, i32* %6
%102 = icmp eq i32 %101, 0
br i1 %102, label %103, label %111
103: ; preds = %96
%104 = load i8**, i8*** %5
%105 = getelementptr inbounds i8*, i8** %104, i64 1
%106 = load i8*, i8** %105
%107 = load i8**, i8*** %5
%108 = getelementptr inbounds i8*, i8** %107, i64 2
%109 = load i8*, i8** %108
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %106, i8* %109)
br label %116
111: ; preds = %96
%112 = load i8**, i8*** %5
%113 = getelementptr inbounds i8*, i8** %112, i64 1
%114 = load i8*, i8** %113
%115 = call i32 @ext_fail(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %114)
br label %116
116: ; preds = %111, %103
%117 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"Syntax: auf2 Quelldatei Zieldatei\0A\00"
@.str.1 = [6 x i8] c"Quell\00"
@O_RDONLY = global i32 0
@.str.2 = [55 x i8] c"Datei '%s' existiert bereits .. \C3\BCberschreiben? (y/N) \00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.5 = [5 x i8] c"Ziel\00"
@.str.6 = [42 x i8] c"Datei '%s' erfolgreich nach '%s' kopiert\0A\00"
@str = [15 x i8] c"\C3\9CBERSCHREIBE!\00"
@str.7 = [30 x i8] c"\C3\9Cberschreibe NICHT!\0ABeende..\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = alloca [1024 x i8]
%6 = bitcast %struct.stat* %3 to i8*
%7 = bitcast %struct.stat* %4 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @stat(i8* %16, %struct.stat* %3)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load i8*, i8** %15
%21 = call i32 @ext_fail(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %14
%23 = load i8*, i8** %15
%24 = load i32, i32* @O_RDONLY
%25 = call i32 (i8*, i32, ...) @open(i8* %23, i32 %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i8*, i8** %15
%29 = call i32 @ext_fail(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %22
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = call i64 @stat(i8* %32, %struct.stat* %4)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %30
%36 = load i8*, i8** %31
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = call signext i8 (...) @getchar()
%39 = icmp eq i8 %38, 121
br i1 %39, label %43, label %40
40: ; preds = %35
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.7, i64 0, i64 0))
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %35
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %45
45: ; preds = %43, %30
%46 = load i8*, i8** %31
%47 = load i32, i32* @O_WRONLY
%48 = load i32, i32* @O_CREAT
%49 = or i32 %48, %47
%50 = load i32, i32* @O_TRUNC
%51 = or i32 %49, %50
%52 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%53 = load i32, i32* %52
%54 = call i32 (i8*, i32, ...) @open(i8* %46, i32 %51, i32 %53)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %45
%57 = load i8*, i8** %31
%58 = call i32 @ext_fail(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %56, %45
%60 = call i32 @read(i32 %25, i8* %8, i32 1024)
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %72
62: ; preds = %59, %69
%63 = phi i32 [ %70, %69 ], [ %60, %59 ]
%64 = call i64 @write(i32 %54, i8* %8, i32 %63)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %62
%67 = load i8*, i8** %31
%68 = call i32 @ext_fail(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %67)
br label %69
69: ; preds = %66, %62
%70 = call i32 @read(i32 %25, i8* %8, i32 1024)
%71 = icmp sgt i32 %70, 0
br i1 %71, label %62, label %72
72: ; preds = %69, %59
%73 = phi i32 [ %60, %59 ], [ %70, %69 ]
%74 = call i32 @close(i32 %25)
%75 = call i32 @close(i32 %54)
%76 = icmp eq i32 %73, 0
%77 = load i8*, i8** %15
br i1 %76, label %78, label %81
78: ; preds = %72
%79 = load i8*, i8** %31
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %77, i8* %79)
br label %83
81: ; preds = %72
%82 = call i32 @ext_fail(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %77)
br label %83
83: ; preds = %81, %78
%84 = call i32 @exit(i32 0)
unreachable
}