#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*/ O_WRONLY;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int /*<<< orphan*/, char *, int);
int write(int, char *, int);
main(int argc, char *argv[]) {
  int n, fd;
  char buf[512];
  if (argc != 2) {
    perror("argumentuak gaizki daude.");
    exit(1);
  };
  ;
  if ((fd = open(argv[1], O_WRONLY)) == -1) {
    perror("open");
    exit(1);
  };
  ;
  while ((n = read(0, buf, 512)) > 0) {
    if (write(1, buf, n) != n) {
      perror("write");
      exit(1);
    };
    ;
    if (write(fd, buf, n) != n) {
      perror("write");
      exit(1);
    };
    ;
  }
  if (n == -1) {
    perror("read");
    exit(1);
  };
  ;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1189 <main+0x39>
lea    0xe86(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11c1 <main+0x71>
lea    0xe68(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11c6 <main+0x76>
lea    -0x220(%rbp),%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1040 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    124e <main+0xfe>
lea    -0x220(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
je     1218 <main+0xc8>
lea    0xe16(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    -0x14(%rbp),%eax
je     1249 <main+0xf9>
lea    0xde5(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11c6 <main+0x76>
cmpl   $0xffffffff,-0x14(%rbp)
jne    126e <main+0x11e>
lea    0xdc6(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
cmp    $0x2,%edi
jne    11f2 <main+0xa2>
mov    0x8(%rsi),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     11fb <main+0xab>
mov    %eax,%r14d
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1040 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11df <main+0x8f>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
jne    11c9 <main+0x79>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
je     1190 <main+0x40>
lea    0xe4f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmp    $0xffffffff,%ebp
je     1204 <main+0xb4>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe07(%rip),%rdi
jmp    11d0 <main+0x80>
lea    0xe18(%rip),%rdi
jmp    11d0 <main+0x80>
lea    0xe1a(%rip),%rdi
jmp    11d0 <main+0x80>

LLVM IR (-O0):
@.str = [26 x i8] c"argumentuak gaizki daude.\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"write\00"
@.str.3 = [5 x i8] c"read\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 [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_WRONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %7
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
br label %25
25: ; preds = %48, %24
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%27 = call i32 @read(i32 0, i8* %26, i32 512)
store i32 %27, i32* %6
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %49
29: ; preds = %25
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%31 = load i32, i32* %6
%32 = call i32 @write(i32 1, i8* %30, i32 %31)
%33 = load i32, i32* %6
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %29
%39 = load i32, i32* %7
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%41 = load i32, i32* %6
%42 = call i32 @write(i32 %39, i8* %40, i32 %41)
%43 = load i32, i32* %6
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38
br label %25
49: ; preds = %25
%50 = load i32, i32* %6
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %49
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [26 x i8] c"argumentuak gaizki daude.\00"
@O_WRONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"write\00"
@.str.3 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_WRONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %9, %27
%19 = call i32 @read(i32 0, i8* %4, i32 512)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = call i32 @write(i32 1, i8* %4, i32 %19)
%23 = icmp eq i32 %22, %19
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %21
%28 = call i32 @write(i32 %13, i8* %4, i32 %19)
%29 = icmp eq i32 %28, %19
br i1 %29, label %18, label %30
30: ; preds = %27
%31 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %18
%34 = icmp eq i32 %19, -1
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %33
ret i32 0
}