#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;
  int /*<<< orphan*/ st_mode;
};
typedef int off_t;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ R_OK;
int /*<<< orphan*/ SEEK_SET;
int S_ISDIR(int /*<<< orphan*/);
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 rmdir(char *);
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("/tmp"
              "/testdir",
              0755);
  assert(ret == 0);
  fd = open("/tmp"
            "/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("/tmp"
               "/testdir"
               "/output.txt",
               R_OK);
  assert(ret == 0);
  ret = stat("/tmp"
             "/testdir"
             "/output.txt",
             &st);
  assert(ret == 0);
  assert(st.st_size == 500);
  ret = unlink("/tmp"
               "/testdir"
               "/output.txt");
  assert(ret == 0);
  ret = stat("/tmp"
             "/testdir"
             "/output.txt",
             &st);
  assert(ret == -1);
  ret = stat("/tmp"
             "/testdir",
             &st);
  assert(ret == 0);
  assert(S_ISDIR(st.st_mode));
  ret = rmdir("/tmp"
              "/testdir");
  assert(ret == 0);
  ret = stat("/tmp"
             "/testdir",
             &st);
  assert(ret == -1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe2a(%rip),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
mov    0x2dbc(%rip),%rax
or     (%rax),%esi
lea    0xe00(%rip),%rdi
mov    $0x1b6,%edx
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x14(%rbp),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
mov    $0x1f3,%esi
call   1080 <lseek@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1f3,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x14(%rbp),%edi
lea    0xdaa(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10e0 <fstat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
cmpl   $0x1f4,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
lea    0xd2d(%rip),%rdi
call   10d0 <access@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xd0d(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10b0 <stat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
cmpl   $0x1f4,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xcd5(%rip),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xcb5(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10b0 <stat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xc84(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10b0 <stat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0xc(%rbp),%edi
call   1070 <S_ISDIR@plt>
mov    %eax,%edi
call   10a0 <assert@plt>
lea    0xc51(%rip),%rdi
call   1060 <rmdir@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    0xc31(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   10b0 <stat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe32(%rip),%r14
mov    %r14,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    0x2e09(%rip),%rax
mov    0x2dca(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe0c(%rip),%r15
mov    %r15,%rdi
mov    $0x1b6,%edx
call   10c0 <open@plt>
mov    %eax,%ebp
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   10a0 <assert@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x1f3,%esi
call   1080 <lseek@plt>
xor    %edi,%edi
cmp    $0x1f3,%eax
sete   %dil
call   10a0 <assert@plt>
lea    0xdc2(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1050 <write@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %rsp,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   10e0 <fstat@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
xor    %edi,%edi
cmpl   $0x1f4,(%rsp)
sete   %dil
call   10a0 <assert@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10d0 <access@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10b0 <stat@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
xor    %edi,%edi
cmpl   $0x1f4,(%rsp)
sete   %dil
call   10a0 <assert@plt>
mov    %r15,%rdi
call   1030 <unlink@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10b0 <stat@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <stat@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    0x4(%rsp),%edi
call   1070 <S_ISDIR@plt>
mov    %eax,%edi
call   10a0 <assert@plt>
mov    %r14,%rdi
call   1060 <rmdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <stat@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   10a0 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [13 x i8] c"/tmp/testdir\00"
@.str.1 = [24 x i8] c"/tmp/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 ([13 x i8], [13 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 ([24 x i8], [24 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 ([24 x i8], [24 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 ([24 x i8], [24 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 ([24 x i8], [24 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 ([24 x i8], [24 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)
%76 = call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
store i32 %76, i32* %4
%77 = load i32, i32* %4
%78 = icmp eq i32 %77, 0
%79 = zext i1 %78 to i32
%80 = call i32 @assert(i32 %79)
%81 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%82 = load i32, i32* %81
%83 = call i32 @S_ISDIR(i32 %82)
%84 = call i32 @assert(i32 %83)
%85 = call i32 @rmdir(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 %85, i32* %4
%86 = load i32, i32* %4
%87 = icmp eq i32 %86, 0
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
%90 = call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
store i32 %90, i32* %4
%91 = load i32, i32* %4
%92 = icmp eq i32 %91, -1
%93 = zext i1 %92 to i32
%94 = call i32 @assert(i32 %93)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str = [13 x i8] c"/tmp/testdir\00"
@.str.1 = [24 x i8] c"/tmp/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 ([13 x i8], [13 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 ([24 x i8], [24 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 ([24 x i8], [24 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 ([24 x i8], [24 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 ([24 x i8], [24 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 ([24 x i8], [24 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)
%58 = call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%59 = icmp eq i32 %58, 0
%60 = zext i1 %59 to i32
%61 = tail call i32 @assert(i32 %60)
%62 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%63 = load i32, i32* %62
%64 = tail call i32 @S_ISDIR(i32 %63)
%65 = tail call i32 @assert(i32 %64)
%66 = tail call i32 @rmdir(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%67 = icmp eq i32 %66, 0
%68 = zext i1 %67 to i32
%69 = tail call i32 @assert(i32 %68)
%70 = call i32 @stat(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%71 = icmp eq i32 %70, -1
%72 = zext i1 %71 to i32
%73 = tail call i32 @assert(i32 %72)
ret i32 0
}