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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDWR;
int close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int write(int, int *, int);
void killtime(void) {
  int i, fd;
  fd = open("/dev/null", O_RDWR);
  for (i = 0; i < 100000000; i++) {
    if (write(fd, &i, sizeof(i)) == -1) {
      do {
        perror("write");
        exit(EXIT_FAILURE);
      } while (0);
    }
  }
  if (close(fd) == -1) {
    do {
      perror("close");
      exit(EXIT_FAILURE);
    } while (0);
  }
  return;
}


x86 assembly (clang, -O0):
<killtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x5f5e100,-0x4(%rbp)
jge    11d0 <killtime+0x80>
mov    -0x8(%rbp),%edi
lea    -0x4(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    11bd <killtime+0x6d>
jmp    11a3 <killtime+0x53>
lea    0xe60(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11c2 <killtime+0x72>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1177 <killtime+0x27>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
jne    1200 <killtime+0xb0>
jmp    11e6 <killtime+0x96>
lea    0xe23(%rip),%rdi
call   1060 <perror@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<killtime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
movl   $0x0,0xc(%rsp)
mov    $0x1,%ebp
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11c8 <killtime+0x78>
mov    %ebp,0xc(%rsp)
add    $0x1,%ebp
cmp    $0x5f5e101,%ebp
jne    1190 <killtime+0x40>
mov    %ebx,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%eax
je     11e2 <killtime+0x92>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe3b(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe27(%rip),%rdi
jmp    11cf <killtime+0x7f>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"write\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [6 x i8] c"close\00"
define void @killtime() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @O_RDWR
%4 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
store i32 0, i32* %1
br label %5
5: ; preds = %19, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 100000000
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = load i32, i32* %2
%10 = call i32 @write(i32 %9, i32* %1, i32 4)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %18
12: ; preds = %8
br label %13
13: ; preds = %12
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; No predecessors!
br label %18
18: ; preds = %17, %8
br label %19
19: ; preds = %18
%20 = load i32, i32* %1
%21 = add nsw i32 %20, 1
store i32 %21, i32* %1
br label %5
22: ; preds = %5
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %22
br label %27
27: ; preds = %26
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; No predecessors!
br label %32
32: ; preds = %31, %22
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"write\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [6 x i8] c"close\00"
define void @killtime() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 0, i32* %1
br label %7
5: ; preds = %7
store i32 %11, i32* %1
%6 = icmp eq i32 %11, 100000000
br i1 %6, label %16, label %7
7: ; preds = %0, %5
%8 = phi i32 [ 0, %0 ], [ %11, %5 ]
%9 = call i32 @write(i32 %4, i32* %1, i32 4)
%10 = icmp eq i32 %9, -1
%11 = add nuw nsw i32 %8, 1
br i1 %10, label %12, label %5
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %5
%17 = tail call i32 @close(i32 %4)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %16
ret void
}