#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 uint8_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int S_IRGRP;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, int *, int);
int main(void) {
  int res;
  int fd = open("/tmp/flush", (O_RDWR | O_CREAT | O_TRUNC),
                (S_IWUSR | S_IRUSR | S_IRGRP | S_IWGRP));
  if (fd < 0) {
    printf("[err] cannot open flush file. errno: %s", strerror(errno));
    exit(-1);
  }
  uint8_t val = 0x1b;
  for (res = 0; res < 128; res++) {
    write(fd, &val, 1);
  }
  close(fd);
  return 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
mov    0x2e79(%rip),%rax
or     (%rax),%esi
mov    0x2e68(%rip),%rax
or     (%rax),%esi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
mov    0x2e0e(%rip),%rax
or     (%rax),%edx
mov    0x2e0d(%rip),%rax
or     (%rax),%edx
mov    0x2e24(%rip),%rax
or     (%rax),%edx
lea    0xe4b(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11ee <main+0x8e>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
movl   $0x1b,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x80,-0x8(%rbp)
jge    1228 <main+0xc8>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11fc <main+0x9c>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    0x2e82(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e6f(%rip),%rax
or     (%rax),%esi
mov    0x2e3e(%rip),%rax
mov    0x2e17(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e14(%rip),%rax
or     (%rax),%edx
mov    0x2e2b(%rip),%rax
or     (%rax),%edx
lea    0xe52(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11f6 <main+0x96>
mov    %eax,%ebx
movl   $0x1b,0xc(%rsp)
mov    $0x80,%ebp
lea    0xc(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0xffffffff,%ebp
jne    11d0 <main+0x70>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe00(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/tmp/flush\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@.str.1 = [40 x i8] c"[err] cannot open flush file. errno: %s\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %5, %6
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IWUSR
%11 = load i32, i32* @S_IRUSR
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRGRP
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IWGRP
%16 = or i32 %14, %15
%17 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %0
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %0
store i32 27, i32* %4
store i32 0, i32* %2
br label %26
26: ; preds = %32, %25
%27 = load i32, i32* %2
%28 = icmp slt i32 %27, 128
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32, i32* %3
%31 = call i32 @write(i32 %30, i32* %4, i32 1)
br label %32
32: ; preds = %29
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
br label %26
35: ; preds = %26
%36 = load i32, i32* %3
%37 = call i32 @close(i32 %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/tmp/flush\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@.str.1 = [40 x i8] c"[err] cannot open flush file. errno: %s\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_TRUNC
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IWUSR
%8 = load i32, i32* @S_IRUSR
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IWGRP
%13 = or i32 %11, %12
%14 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %0
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %0
%22 = bitcast i32* %1 to i8*
store i32 27, i32* %1
br label %23
23: ; preds = %21, %23
%24 = phi i32 [ 0, %21 ], [ %26, %23 ]
%25 = call i32 @write(i32 %14, i32* %1, i32 1)
%26 = add nuw nsw i32 %24, 1
%27 = icmp eq i32 %26, 128
br i1 %27, label %28, label %23
28: ; preds = %23
%29 = tail call i32 @close(i32 %14)
ret i32 0
}