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

/* Variables and functions */
int O_APPEND;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
char getchar();
int /*<<< orphan*/ gets(char *);
scalar_t__ isClientDone();
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char reply[256] = "";
  char msg[256] = "";
  int answer_file = open("wyniki.txt", O_WRONLY | O_APPEND);
  while (1) {
    if (isClientDone()) {
      remove("done");
      FILE *data_file = fopen("dane.txt", "r");
      while (fgets(msg, 256, data_file) != NULL) {
        printf("%s", msg);
      }
      fclose(data_file);
      printf("\n");
      char ch;
      do {
        gets(reply);
        ch = getchar();
      } while (ch != '\x1b' && ch != '\n');
      FILE *clear_data = fopen("wyniki.txt", "w");
      fclose(clear_data);
      int answer_file = open("wyniki.txt", O_WRONLY | O_APPEND);
      write(answer_file, reply, 256);
      close(answer_file);
      FILE *done = fopen("done", "w");
      fprintf(done, "done");
      fclose(done);
      sleep(10);
      remove("lockfile");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
mov    0x2da1(%rip),%rax
or     (%rax),%esi
lea    0xdc8(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,-0x214(%rbp)
mov    $0x0,%al
call   10c0 <isClientDone@plt>
cmp    $0x0,%rax
je     13dd <main+0x1fd>
lea    0xdb0(%rip),%rdi
call   1030 <remove@plt>
lea    0xda9(%rip),%rdi
lea    0xdab(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x220(%rbp),%rdx
mov    $0x100,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     12b6 <main+0xd6>
lea    -0x210(%rbp),%rsi
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    127a <main+0x9a>
mov    -0x220(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x110(%rbp),%rdi
call   10d0 <gets@plt>
mov    $0x0,%al
call   10a0 <getchar@plt>
mov    %al,-0x221(%rbp)
movsbl -0x221(%rbp),%ecx
xor    %eax,%eax
cmp    $0x1b,%ecx
mov    %al,-0x241(%rbp)
je     1314 <main+0x134>
movsbl -0x221(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x241(%rbp)
mov    -0x241(%rbp),%al
test   $0x1,%al
jne    12d0 <main+0xf0>
lea    0xcd7(%rip),%rdi
lea    0xcf0(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x230(%rbp)
mov    -0x230(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%esi
mov    0x2c78(%rip),%rax
or     (%rax),%esi
lea    0xc9f(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,-0x234(%rbp)
mov    -0x234(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1040 <write@plt>
mov    -0x234(%rbp),%edi
call   1080 <close@plt>
lea    0xc76(%rip),%rdi
lea    0xc84(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x240(%rbp)
mov    -0x240(%rbp),%rdi
lea    0xc55(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x240(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0xa,%edi
call   1100 <sleep@plt>
lea    0xc4a(%rip),%rdi
call   1030 <remove@plt>
jmp    1243 <main+0x63>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2cf6(%rip),%rax
mov    0x2ce7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xd0c(%rip),%rdi
call   10d0 <open@plt>
lea    0xd0b(%rip),%r13
mov    %rsp,%rbx
lea    0x100(%rsp),%r15
lea    0xd09(%rip),%r12
jmp    13b4 <main+0x1d4>
nopw   0x0(%rax,%rax,1)
lea    0xcd9(%rip),%rbp
mov    %rbp,%rdi
lea    0xced(%rip),%r14
mov    %r14,%rsi
call   10e0 <fopen@plt>
mov    %rax,%rdi
call   1060 <fclose@plt>
mov    0x2c88(%rip),%rax
mov    (%rax),%esi
mov    0x2c87(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
call   10d0 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   10e0 <fopen@plt>
mov    %rax,%rbp
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r13,%rdi
mov    %rax,%rcx
call   10f0 <fwrite@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    $0xa,%edi
call   1100 <sleep@plt>
lea    0xc71(%rip),%rdi
call   1040 <remove@plt>
xor    %eax,%eax
call   10b0 <isClientDone@plt>
test   %rax,%rax
je     13b4 <main+0x1d4>
mov    %r13,%rdi
call   1040 <remove@plt>
lea    0xc41(%rip),%rdi
lea    0xc43(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
nopl   0x0(%rax)
call   1090 <fgets@plt>
test   %rax,%rax
je     1420 <main+0x240>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
jmp    13f0 <main+0x210>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
call   10c0 <gets@plt>
xor    %eax,%eax
call   10a0 <getchar@plt>
cmp    $0x1b,%al
je     1320 <main+0x140>
cmp    $0xa,%al
jne    1440 <main+0x260>
jmp    1320 <main+0x140>

LLVM IR (-O0):
@.str = [11 x i8] c"wyniki.txt\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str.1 = [5 x i8] c"done\00"
@.str.2 = [9 x i8] c"dane.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [9 x i8] c"lockfile\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i8
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast [256 x i8]* %6 to i8*
%15 = bitcast [256 x i8]* %7 to i8*
%16 = load i32, i32* @O_WRONLY
%17 = load i32, i32* @O_APPEND
%18 = or i32 %16, %17
%19 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 %19, i32* %8
br label %20
20: ; preds = %2, %72
%21 = call i64 (...) @isClientDone()
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %72
23: ; preds = %20
%24 = call i32 @remove(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %25, i32** %9
br label %26
26: ; preds = %31, %23
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%28 = load i32*, i32** %9
%29 = call i32* @fgets(i8* %27, i32 256, i32* %28)
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %32)
br label %26
34: ; preds = %26
%35 = load i32*, i32** %9
%36 = call i32 @fclose(i32* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %50, %34
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%40 = call i32 @gets(i8* %39)
%41 = call signext i8 (...) @getchar()
store i8 %41, i8* %10
br label %42
42: ; preds = %38
%43 = load i8, i8* %10
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 27
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i8, i8* %10
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 10
br label %50
50: ; preds = %46, %42
%51 = phi i1 [ false, %42 ], [ %49, %46 ]
br i1 %51, label %38, label %52
52: ; preds = %50
%53 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %53, i32** %11
%54 = load i32*, i32** %11
%55 = call i32 @fclose(i32* %54)
%56 = load i32, i32* @O_WRONLY
%57 = load i32, i32* @O_APPEND
%58 = or i32 %56, %57
%59 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %58)
store i32 %59, i32* %12
%60 = load i32, i32* %12
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%62 = call i32 @write(i32 %60, i8* %61, i32 256)
%63 = load i32, i32* %12
%64 = call i32 @close(i32 %63)
%65 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %65, i32** %13
%66 = load i32*, i32** %13
%67 = call i32 @fprintf(i32* %66, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%68 = load i32*, i32** %13
%69 = call i32 @fclose(i32* %68)
%70 = call i32 @sleep(i32 10)
%71 = call i32 @remove(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %72
72: ; preds = %52, %20
br label %20
}

LLVM IR (-O2):
@.str = [11 x i8] c"wyniki.txt\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str.1 = [5 x i8] c"done\00"
@.str.2 = [9 x i8] c"dane.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [9 x i8] c"lockfile\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_APPEND
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %43, %2
%12 = call i64 (...) @isClientDone()
%13 = icmp eq i64 %12, 0
br i1 %13, label %43, label %14
14: ; preds = %11
%15 = call i32 @remove(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32* @fgets(i8* %6, i32 256, i32* %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %23, label %19
19: ; preds = %14, %19
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%21 = call i32* @fgets(i8* %6, i32 256, i32* %16)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %19
23: ; preds = %19, %14
%24 = call i32 @fclose(i32* %16)
%25 = call i32 @putchar(i32 10)
br label %26
26: ; preds = %26, %23
%27 = call i32 @gets(i8* %5)
%28 = call signext i8 (...) @getchar()
switch i8 %28, label %26 [
i8 27, label %29
i8 10, label %29
]
29: ; preds = %26, %26
%30 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* @O_WRONLY
%33 = load i32, i32* @O_APPEND
%34 = or i32 %33, %32
%35 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = call i32 @write(i32 %35, i8* %5, i32 256)
%37 = call i32 @close(i32 %35)
%38 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%39 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 4, i64 1, i32* %38)
%40 = call i32 @fclose(i32* %38)
%41 = call i32 @sleep(i32 10)
%42 = call i32 @remove(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %43
43: ; preds = %29, %11
br label %11
}