#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int, ...);
scalar_t__ read(int, char *, int);
int strlen(char *);
scalar_t__ write(int, char *, int);
int main(void) {
  int in, out;
  char c;
  if ((in = open("plik_we.txt", O_RDONLY)) == -1) {
    if (write(2, "Nie można otworzyć pliku wejściowego.\n",
              strlen("Nie można otworzyć pliku wejściowego.\n"))) {
    };
    exit(1);
  }
  if ((out = open("plik_wy.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666)) == -1) {
    if (write(2, "Nie można otworzyć pliku wyjściowego.\n",
              strlen("Nie można otworzyć pliku wyjściowego.\n"))) {
    };
    exit(2);
  }
  while (read(in, &c, 1))
    if (write(out, &c, 1)) {
    };
  close(in);
  close(out);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11ca <main+0x6a>
lea    0xe73(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0xe60(%rip),%rsi
call   1030 <write@plt>
cmp    $0x0,%rax
je     11c0 <main+0x60>
jmp    11c0 <main+0x60>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    0x2de6(%rip),%rax
or     (%rax),%esi
mov    0x2e0d(%rip),%rax
or     (%rax),%esi
lea    0xe4a(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    123c <main+0xdc>
lea    0xe37(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0xe24(%rip),%rsi
call   1030 <write@plt>
cmp    $0x0,%rax
je     1232 <main+0xd2>
jmp    1232 <main+0xd2>
mov    $0x2,%edi
call   1080 <exit@plt>
jmp    1241 <main+0xe1>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
je     1281 <main+0x121>
mov    -0xc(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
je     127c <main+0x11c>
jmp    127c <main+0x11c>
jmp    1241 <main+0xe1>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1070 <open@plt>
cmp    $0xffffffff,%eax
jne    11ac <main+0x4c>
lea    0xe81(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %eax,%r14d
mov    0x2e42(%rip),%rax
mov    0x2e03(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e28(%rip),%rax
or     (%rax),%esi
lea    0xe65(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1070 <open@plt>
cmp    $0xffffffff,%eax
jne    120a <main+0xaa>
lea    0xe59(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    %eax,%ebp
lea    0xf(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
je     1254 <main+0xf4>
lea    0xf(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
jne    1230 <main+0xd0>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"plik_we.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [42 x i8] c"Nie mo\C5\BCna otworzy\C4\87 pliku wej\C5\9Bciowego.\0A\00"
@.str.2 = [12 x i8] c"plik_wy.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [42 x i8] c"Nie mo\C5\BCna otworzy\C4\87 pliku wyj\C5\9Bciowego.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = call i32 @strlen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%10 = call i64 @write(i32 2, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
br label %13
13: ; preds = %12, %8
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load i32, i32* @O_CREAT
%17 = load i32, i32* @O_WRONLY
%18 = or i32 %16, %17
%19 = load i32, i32* @O_TRUNC
%20 = or i32 %18, %19
%21 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 438)
store i32 %21, i32* %3
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %30
23: ; preds = %15
%24 = call i32 @strlen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%25 = call i64 @write(i32 2, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
br label %28
28: ; preds = %27, %23
%29 = call i32 @exit(i32 2)
unreachable
30: ; preds = %15
br label %31
31: ; preds = %40, %30
%32 = load i32, i32* %2
%33 = call i64 @read(i32 %32, i8* %4, i32 1)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %31
%36 = load i32, i32* %3
%37 = call i64 @write(i32 %36, i8* %4, i32 1)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
br label %40
40: ; preds = %39, %35
br label %31
41: ; preds = %31
%42 = load i32, i32* %2
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %3
%45 = call i32 @close(i32 %44)
%46 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"plik_we.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [42 x i8] c"Nie mo\C5\BCna otworzy\C4\87 pliku wej\C5\9Bciowego.\0A\00"
@.str.2 = [12 x i8] c"plik_wy.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [42 x i8] c"Nie mo\C5\BCna otworzy\C4\87 pliku wyj\C5\9Bciowego.\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i64 @write(i32 2, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_WRONLY
%12 = or i32 %11, %10
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %12, %13
%15 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 438)
%16 = icmp eq i32 %15, -1
br i1 %16, label %20, label %17
17: ; preds = %9
%18 = call i64 @read(i32 %3, i8* %1, i32 1)
%19 = icmp eq i64 %18, 0
br i1 %19, label %28, label %24
20: ; preds = %9
%21 = tail call i32 @strlen(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%22 = tail call i64 @write(i32 2, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = tail call i32 @exit(i32 2)
unreachable
24: ; preds = %17, %24
%25 = call i64 @write(i32 %15, i8* %1, i32 1)
%26 = call i64 @read(i32 %3, i8* %1, i32 1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %24
28: ; preds = %24, %17
%29 = tail call i32 @close(i32 %3)
%30 = tail call i32 @close(i32 %15)
%31 = tail call i32 @exit(i32 0)
unreachable
}