#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_RDWR;
void *atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd = open(argv[1], O_RDWR);
  if (fd == -1) {
    perror("open");
    return -1;
  }
  int end = 0;
  char *buffer = calloc(8, sizeof(char) * 8);
  char *stdBuffer = calloc(8, sizeof(char) * 4);
  while (!end) {
    bzero(stdBuffer, 4);
    buffer[0] = 0x00;
    buffer[1] = 0x08;
    buffer[2] = 0x00;
    buffer[3] = 0x00;
    buffer[4] = 0x00;
    buffer[5] = 0x00;
    buffer[6] = 0x00;
    buffer[7] = 0x00;
    printf("Links (0) oder rechts (1) oder abbrechen (-1)?\n");
    read(0, stdBuffer, 2);
    fflush(0);
    int number = atoi(stdBuffer);
    if (number == -1) {
      end = 1;
    } else {
      printf("Staerke?\n");
      read(0, stdBuffer, 4);
      fflush(0);
      if (number == 0) {
        buffer[3] = atoi(stdBuffer);
      } else {
        buffer[4] = atoi(stdBuffer);
      }
      int size = write(fd, buffer, 8);
      printf("Size written: %d\n", size);
    }
  }
  free(buffer);
  free(stdBuffer);
  close(fd);
  printf("Close..\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1201 <main+0x51>
lea    0xe10(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1386 <main+0x1d6>
movl   $0x0,-0x18(%rbp)
mov    $0x8,%esi
mov    %esi,%edi
call   1080 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x8,%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1241 <main+0x91>
jmp    1357 <main+0x1a7>
mov    -0x28(%rbp),%rdi
mov    $0x4,%esi
call   10c0 <bzero@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x8,0x1(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x5(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x6(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x7(%rax)
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
mov    $0x2,%edx
call   1070 <read@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
mov    -0x28(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    12d5 <main+0x125>
movl   $0x1,-0x18(%rbp)
jmp    1352 <main+0x1a2>
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
xor    %edi,%edi
mov    $0x4,%edx
call   1070 <read@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    131b <main+0x16b>
mov    -0x28(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x3(%rax)
jmp    132d <main+0x17d>
mov    -0x28(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1040 <write@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%esi
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    122b <main+0x7b>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
lea    0xcd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     1301 <main+0x141>
mov    %eax,%r14d
mov    $0x8,%edi
mov    $0x8,%esi
call   1090 <calloc@plt>
mov    %rax,%rbx
mov    $0x8,%edi
mov    $0x4,%esi
call   1090 <calloc@plt>
mov    %rax,%rbp
lea    0x2(%rbx),%r15
lea    0xded(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x4,%esi
call   10d0 <bzero@plt>
movw   $0x800,(%rbx)
movl   $0x0,(%r15)
movw   $0x0,0x4(%r15)
lea    0xdd8(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1080 <read@plt>
xor    %edi,%edi
call   10a0 <fflush@plt>
mov    %rbp,%rdi
call   10e0 <atoi@plt>
mov    %rax,%r12
cmp    $0xffffffff,%r12d
je     12cc <main+0x10c>
lea    0xdd4(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1080 <read@plt>
xor    %edi,%edi
call   10a0 <fflush@plt>
mov    %rbp,%rdi
call   10e0 <atoi@plt>
cmp    $0x1,%r12d
mov    %rbx,%rcx
sbb    $0x0,%rcx
mov    %al,0x4(%rcx)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1050 <write@plt>
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1220 <main+0x60>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   1070 <close@plt>
lea    0xd2c(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf8(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%eax
jmp    12f2 <main+0x132>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [5 x i8] c"open\00"
@.str.1 = [48 x i8] c"Links (0) oder rechts (1) oder abbrechen (-1)?\0A\00"
@.str.2 = [10 x i8] c"Staerke?\0A\00"
@.str.3 = [18 x i8] c"Size written: %d\0A\00"
@.str.4 = [9 x i8] c"Close..\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 i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %91
21: ; preds = %2
store i32 0, i32* %7
%22 = call i8* @calloc(i32 8, i32 8)
store i8* %22, i8** %8
%23 = call i8* @calloc(i32 8, i32 4)
store i8* %23, i8** %9
br label %24
24: ; preds = %82, %21
%25 = load i32, i32* %7
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %83
28: ; preds = %24
%29 = load i8*, i8** %9
%30 = call i32 @bzero(i8* %29, i32 4)
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i64 0
store i8 0, i8* %32
%33 = load i8*, i8** %8
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8 8, i8* %34
%35 = load i8*, i8** %8
%36 = getelementptr inbounds i8, i8* %35, i64 2
store i8 0, i8* %36
%37 = load i8*, i8** %8
%38 = getelementptr inbounds i8, i8* %37, i64 3
store i8 0, i8* %38
%39 = load i8*, i8** %8
%40 = getelementptr inbounds i8, i8* %39, i64 4
store i8 0, i8* %40
%41 = load i8*, i8** %8
%42 = getelementptr inbounds i8, i8* %41, i64 5
store i8 0, i8* %42
%43 = load i8*, i8** %8
%44 = getelementptr inbounds i8, i8* %43, i64 6
store i8 0, i8* %44
%45 = load i8*, i8** %8
%46 = getelementptr inbounds i8, i8* %45, i64 7
store i8 0, i8* %46
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%48 = load i8*, i8** %9
%49 = call i32 @read(i32 0, i8* %48, i32 2)
%50 = call i32 @fflush(i32 0)
%51 = load i8*, i8** %9
%52 = call i8* @atoi(i8* %51)
%53 = ptrtoint i8* %52 to i32
store i32 %53, i32* %10
%54 = load i32, i32* %10
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %57
56: ; preds = %28
store i32 1, i32* %7
br label %82
57: ; preds = %28
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%59 = load i8*, i8** %9
%60 = call i32 @read(i32 0, i8* %59, i32 4)
%61 = call i32 @fflush(i32 0)
%62 = load i32, i32* %10
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %70
64: ; preds = %57
%65 = load i8*, i8** %9
%66 = call i8* @atoi(i8* %65)
%67 = ptrtoint i8* %66 to i8
%68 = load i8*, i8** %8
%69 = getelementptr inbounds i8, i8* %68, i64 3
store i8 %67, i8* %69
br label %76
70: ; preds = %57
%71 = load i8*, i8** %9
%72 = call i8* @atoi(i8* %71)
%73 = ptrtoint i8* %72 to i8
%74 = load i8*, i8** %8
%75 = getelementptr inbounds i8, i8* %74, i64 4
store i8 %73, i8* %75
br label %76
76: ; preds = %70, %64
%77 = load i32, i32* %6
%78 = load i8*, i8** %8
%79 = call i32 @write(i32 %77, i8* %78, i32 8)
store i32 %79, i32* %11
%80 = load i32, i32* %11
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %76, %56
br label %24
83: ; preds = %24
%84 = load i8*, i8** %8
%85 = call i32 @free(i8* %84)
%86 = load i8*, i8** %9
%87 = call i32 @free(i8* %86)
%88 = load i32, i32* %6
%89 = call i32 @close(i32 %88)
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %91
91: ; preds = %83, %19
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [5 x i8] c"open\00"
@.str.3 = [18 x i8] c"Size written: %d\0A\00"
@str = [8 x i8] c"Close..\00"
@str.5 = [47 x i8] c"Links (0) oder rechts (1) oder abbrechen (-1)?\00"
@str.6 = [9 x i8] c"Staerke?\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %41
10: ; preds = %2
%11 = tail call dereferenceable_or_null(64) i8* @calloc(i32 8, i32 8)
%12 = tail call dereferenceable_or_null(32) i8* @calloc(i32 8, i32 4)
%13 = getelementptr inbounds i8, i8* %11, i64 1
%14 = getelementptr inbounds i8, i8* %11, i64 2
br label %15
15: ; preds = %24, %10
%16 = tail call i32 @bzero(i8* %12, i32 4)
store i8 0, i8* %11
store i8 8, i8* %13
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.5, i64 0, i64 0))
%18 = tail call i32 @read(i32 0, i8* %12, i32 2)
%19 = tail call i32 @fflush(i32 0)
%20 = tail call i8* @atoi(i8* %12)
%21 = ptrtoint i8* %20 to i64
%22 = trunc i64 %21 to i32
%23 = icmp eq i32 %22, -1
br i1 %23, label %36, label %24
24: ; preds = %15
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.6, i64 0, i64 0))
%26 = tail call i32 @read(i32 0, i8* %12, i32 4)
%27 = tail call i32 @fflush(i32 0)
%28 = icmp eq i32 %22, 0
%29 = tail call i8* @atoi(i8* %12)
%30 = ptrtoint i8* %29 to i64
%31 = trunc i64 %30 to i8
%32 = select i1 %28, i64 3, i64 4
%33 = getelementptr inbounds i8, i8* %11, i64 %32
store i8 %31, i8* %33
%34 = tail call i32 @write(i32 %6, i8* %11, i32 8)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %15
36: ; preds = %15
%37 = tail call i32 @free(i8* %11)
%38 = tail call i32 @free(i8* %12)
%39 = tail call i32 @close(i32 %6)
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %41
41: ; preds = %36, %8
%42 = phi i32 [ -1, %8 ], [ 0, %36 ]
ret i32 %42
}