#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 O_RDONLY;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ftruncate(int, int /*<<< orphan*/);
int open(char *, int, ...);
scalar_t__ read(int, char *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int a;
  char buf[sizeof("seier")];
  a = open("a", O_RDWR | O_TRUNC | O_CREAT, 0644);
  write(a, "lullerbullertruller", sizeof("lullerbullertruller"));
  close(a);
  a = open("a", O_RDWR);
  ftruncate(a, 0);
  write(a, "seier", sizeof("seier"));
  close(a);
  a = open("a", O_RDONLY);
  if (a < 0)
    abort();
  if (read(a, buf, sizeof("seier")) < 0)
    abort();
  if (strncmp(buf, "seier", sizeof("seier")))
    abort();
  close(a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
mov    0x2e5a(%rip),%rax
or     (%rax),%esi
mov    0x2e59(%rip),%rax
or     (%rax),%esi
lea    0xe58(%rip),%rdi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    0xe41(%rip),%rsi
mov    $0x14,%edx
call   1050 <write@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1060 <ftruncate@plt>
mov    -0x14(%rbp),%edi
lea    0xe15(%rip),%rsi
mov    $0x6,%edx
call   1050 <write@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    123e <main+0xce>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x14(%rbp),%edi
lea    -0x1a(%rbp),%rsi
mov    $0x6,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
jge    1260 <main+0xf0>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x1a(%rbp),%rdi
lea    0xdab(%rip),%rsi
mov    $0x6,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1286 <main+0x116>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e59(%rip),%r14
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
or     (%r14),%esi
mov    0x2e66(%rip),%rax
or     (%rax),%esi
lea    0xe65(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,%ebp
lea    0xe4f(%rip),%rsi
mov    %eax,%edi
mov    $0x14,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    (%r14),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
call   1060 <ftruncate@plt>
lea    0xe31(%rip),%rsi
mov    %ebp,%edi
mov    $0x6,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <open@plt>
test   %eax,%eax
js     1254 <main+0xe4>
mov    %eax,%ebx
lea    0xa(%rsp),%rsi
mov    %eax,%edi
mov    $0x6,%edx
call   1080 <read@plt>
test   %rax,%rax
js     1254 <main+0xe4>
lea    0xde8(%rip),%rsi
lea    0xa(%rsp),%rdi
mov    $0x6,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1254 <main+0xe4>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.1 = [20 x i8] c"lullerbullertruller\00"
@.str.2 = [6 x i8] c"seier\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [6 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %12, i32 420)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = call i32 @write(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 20)
%16 = load i32, i32* %6
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* @O_RDWR
%19 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = call i32 @ftruncate(i32 %20, i32 0)
%22 = load i32, i32* %6
%23 = call i32 @write(i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 6)
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* @O_RDONLY
%27 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %2
%31 = call i32 (...) @abort()
unreachable
32: ; preds = %2
%33 = load i32, i32* %6
%34 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%35 = call i64 @read(i32 %33, i8* %34, i32 6)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 (...) @abort()
unreachable
39: ; preds = %32
%40 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%41 = call i64 @strncmp(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 6)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 (...) @abort()
unreachable
45: ; preds = %39
%46 = load i32, i32* %6
%47 = call i32 @close(i32 %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.1 = [20 x i8] c"lullerbullertruller\00"
@.str.2 = [6 x i8] c"seier\00"
@O_RDONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %6, %5
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %9, i32 420)
%11 = tail call i32 @write(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 20)
%12 = tail call i32 @close(i32 %10)
%13 = load i32, i32* @O_RDWR
%14 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = tail call i32 @ftruncate(i32 %14, i32 0)
%16 = tail call i32 @write(i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 6)
%17 = tail call i32 @close(i32 %14)
%18 = load i32, i32* @O_RDONLY
%19 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = tail call i32 (...) @abort()
unreachable
23: ; preds = %2
%24 = call i64 @read(i32 %19, i8* %4, i32 6)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = tail call i32 (...) @abort()
unreachable
28: ; preds = %23
%29 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 6)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 (...) @abort()
unreachable
33: ; preds = %28
%34 = call i32 @close(i32 %19)
ret i32 0
}