#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*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ write(int, char *, int);
void write_log(int fd) {
  char buf[(8 * 1024)];
  int i;
  for (;;) {
    for (i = 0; i < (10 * 1024 * 1024) / (8 * 1024); i++) {
      if (write(fd, buf, (8 * 1024)) < 0) {
        printf("ERROR: write error.\n");
        exit(2);
      }
    }
    if (lseek(fd, 0, SEEK_SET) < 0) {
      printf("ERROR: seek() failed.\n");
      exit(3);
    }
  }
}


x86 assembly (clang, -O0):
<write_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x2014(%rbp)
cmpl   $0x500,-0x2014(%rbp)
jge    11b5 <write_log+0x75>
mov    -0x4(%rbp),%edi
lea    -0x2010(%rbp),%rsi
mov    $0x2000,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    119c <write_log+0x5c>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
jmp    11a1 <write_log+0x61>
mov    -0x2014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2014(%rbp)
jmp    1158 <write_log+0x18>
mov    -0x4(%rbp),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    11e8 <write_log+0xa8>
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3,%edi
call   1060 <exit@plt>
jmp    114e <write_log+0xe>

x86 assembly (clang, -O2):
<write_log>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2008,%rsp
mov    %edi,%ebx
xor    %ebp,%ebp
mov    %rsp,%r14
mov    0x2e85(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2000,%edx
call   1040 <write@plt>
test   %rax,%rax
js     11a8 <write_log+0x68>
add    $0x1,%ebp
cmp    $0x500,%ebp
jne    1160 <write_log+0x20>
mov    (%r15),%edx
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
test   %rax,%rax
jns    1160 <write_log+0x20>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3,%edi
call   1060 <exit@plt>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"ERROR: write error.\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [23 x i8] c"ERROR: seek() failed.\0A\00"
define void @write_log(i32 %0) {
%2 = alloca i32
%3 = alloca [8192 x i8]
%4 = alloca i32
store i32 %0, i32* %2
br label %5
5: ; preds = %29, %1
store i32 0, i32* %4
br label %6
6: ; preds = %18, %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1280
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = load i32, i32* %2
%11 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%12 = call i64 @write(i32 %10, i8* %11, i32 8192)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 2)
unreachable
17: ; preds = %9
br label %18
18: ; preds = %17
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %6
21: ; preds = %6
%22 = load i32, i32* %2
%23 = load i32, i32* @SEEK_SET
%24 = call i64 @lseek(i32 %22, i32 0, i32 %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 3)
unreachable
29: ; preds = %21
br label %5
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@str = [22 x i8] c"ERROR: seek() failed.\00"
@str.2 = [20 x i8] c"ERROR: write error.\00"
define void @write_log(i32 %0) {
%2 = alloca [8192 x i8]
%3 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
br label %9
4: ; preds = %9
%5 = add nuw nsw i32 %10, 1
%6 = icmp eq i32 %5, 1280
br i1 %6, label %16, label %7
7: ; preds = %4, %16
%8 = phi i32 [ %5, %4 ], [ 0, %16 ]
br label %9
9: ; preds = %7, %1
%10 = phi i32 [ 0, %1 ], [ %8, %7 ]
%11 = call i64 @write(i32 %0, i8* %3, i32 8192)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %4
13: ; preds = %9
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 2)
unreachable
16: ; preds = %4
%17 = load i32, i32* @SEEK_SET
%18 = tail call i64 @lseek(i32 %0, i32 0, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %7
20: ; preds = %16
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 @exit(i32 3)
unreachable
}