#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 */
struct stat {
  int st_size;
};
typedef int off_t;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ R_OK;
int /*<<< orphan*/ SEEK_SET;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ assert(int);
int close(int);
int fstat(int, struct stat *);
int lseek(int, int, int /*<<< orphan*/);
int mkdir(char *, int);
int open(char *, int, int);
int stat(char *, struct stat *);
int unlink(char *);
scalar_t__ write(int, char *, int);
int main(void) {
  struct stat st;
  int fd;
  int ret;
  off_t pos;
  (void)st;
  ret = mkdir("/sandbox"
              "/testdir",
              0755);
  assert(ret == 0);
  fd = open("/sandbox"
            "/testdir"
            "/output.txt",
            O_CREAT | O_WRONLY, 0666);
  assert(fd != -1);
  pos = lseek(fd, 500 - 1, SEEK_SET);
  assert(pos == 500 - 1);
  ret = (int)write(fd, "", 1);
  assert(ret == 1);
  ret = fstat(fd, &st);
  assert(ret == 0);
  assert(st.st_size == 500);
  ret = close(fd);
  assert(ret == 0);
  ret = access("/sandbox"
               "/testdir"
               "/output.txt",
               R_OK);
  assert(ret == 0);
  ret = stat("/sandbox"
             "/testdir"
             "/output.txt",
             &st);
  assert(ret == 0);
  assert(st.st_size == 500);
  ret = unlink("/sandbox"
               "/testdir"
               "/output.txt");
  assert(ret == 0);
  ret = stat("/sandbox"
             "/testdir"
             "/output.txt",
             &st);
  assert(ret == -1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
mov    0x2ddc(%rip),%rax
or     (%rax),%esi
lea    0xe24(%rip),%rdi
mov    $0x1b6,%edx
call   10a0 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0xc(%rbp),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
mov    $0x1f3,%esi
call   1060 <lseek@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1f3,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0xc(%rbp),%edi
lea    0xdce(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   10c0 <fstat@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpl   $0x1f4,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
lea    0xd51(%rip),%rdi
call   10b0 <access@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    0xd31(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1090 <stat@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpl   $0x1f4,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    0xcf9(%rip),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    0xcd9(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1090 <stat@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe51(%rip),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
mov    0x2e2b(%rip),%rax
mov    0x2dec(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe32(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   10a0 <open@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1080 <assert@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x1f3,%esi
call   1060 <lseek@plt>
xor    %edi,%edi
cmp    $0x1f3,%eax
sete   %dil
call   1080 <assert@plt>
lea    0xde8(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1050 <write@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1080 <assert@plt>
lea    0x8(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rsi
call   10c0 <fstat@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
xor    %edi,%edi
cmpl   $0x1f4,0x8(%rsp)
sete   %dil
call   1080 <assert@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <access@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <stat@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
xor    %edi,%edi
cmpl   $0x1f4,0x8(%rsp)
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <stat@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1080 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [17 x i8] c"/sandbox/testdir\00"
@.str.1 = [28 x i8] c"/sandbox/testdir/output.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@R_OK = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @mkdir(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 493)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_WRONLY
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 438)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, -1
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* %3
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @lseek(i32 %19, i32 499, i32 %20)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 499
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* %3
%27 = call i64 @write(i32 %26, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 1)
%28 = trunc i64 %27 to i32
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 1
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i32, i32* %3
%34 = call i32 @fstat(i32 %33, %struct.stat* %2)
store i32 %34, i32* %4
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 500
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i32, i32* %3
%45 = call i32 @close(i32 %44)
store i32 %45, i32* %4
%46 = load i32, i32* %4
%47 = icmp eq i32 %46, 0
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i32, i32* @R_OK
%51 = call i32 @access(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %50)
store i32 %51, i32* %4
%52 = load i32, i32* %4
%53 = icmp eq i32 %52, 0
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = call i32 @stat(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %2)
store i32 %56, i32* %4
%57 = load i32, i32* %4
%58 = icmp eq i32 %57, 0
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%62 = load i32, i32* %61
%63 = icmp eq i32 %62, 500
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
%66 = call i32 @unlink(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 %66, i32* %4
%67 = load i32, i32* %4
%68 = icmp eq i32 %67, 0
%69 = zext i1 %68 to i32
%70 = call i32 @assert(i32 %69)
%71 = call i32 @stat(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %2)
store i32 %71, i32* %4
%72 = load i32, i32* %4
%73 = icmp eq i32 %72, -1
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [17 x i8] c"/sandbox/testdir\00"
@.str.1 = [28 x i8] c"/sandbox/testdir/output.txt\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@R_OK = global i32 0
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i32 @mkdir(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 493)
%4 = icmp eq i32 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = load i32, i32* @O_CREAT
%8 = load i32, i32* @O_WRONLY
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 438)
%11 = icmp ne i32 %10, -1
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @lseek(i32 %10, i32 499, i32 %14)
%16 = icmp eq i32 %15, 499
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i64 @write(i32 %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 1)
%20 = trunc i64 %19 to i32
%21 = icmp eq i32 %20, 1
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = call i32 @fstat(i32 %10, %struct.stat* %1)
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 500
%31 = zext i1 %30 to i32
%32 = tail call i32 @assert(i32 %31)
%33 = tail call i32 @close(i32 %10)
%34 = icmp eq i32 %33, 0
%35 = zext i1 %34 to i32
%36 = tail call i32 @assert(i32 %35)
%37 = load i32, i32* @R_OK
%38 = tail call i32 @access(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = icmp eq i32 %38, 0
%40 = zext i1 %39 to i32
%41 = tail call i32 @assert(i32 %40)
%42 = call i32 @stat(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %1)
%43 = icmp eq i32 %42, 0
%44 = zext i1 %43 to i32
%45 = tail call i32 @assert(i32 %44)
%46 = load i32, i32* %28
%47 = icmp eq i32 %46, 500
%48 = zext i1 %47 to i32
%49 = tail call i32 @assert(i32 %48)
%50 = tail call i32 @unlink(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%51 = icmp eq i32 %50, 0
%52 = zext i1 %51 to i32
%53 = tail call i32 @assert(i32 %52)
%54 = call i32 @stat(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %1)
%55 = icmp eq i32 %54, -1
%56 = zext i1 %55 to i32
%57 = tail call i32 @assert(i32 %56)
ret i32 0
}