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

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ assert(int);
scalar_t__ close(int);
scalar_t__ fstat(int, struct stat *);
scalar_t__ ftruncate(int, int);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ mkdir(char *, int);
int open(char *, int, int);
int main(void) {
  struct stat st;
  int fd;
  (void)st;
  assert(0 == mkdir("/tmp"
                    "/testdir",
                    0755));
  fd = open("/tmp"
            "/testdir"
            "/output.txt",
            O_CREAT | O_WRONLY, 0666);
  assert(fd != -1);
  assert(0 == fstat(fd, &st));
  assert(st.st_size == 0);
  assert(0 == lseek(fd, 0, SEEK_CUR));
  assert(0 == ftruncate(fd, 500));
  assert(0 == fstat(fd, &st));
  assert(st.st_size == 500);
  assert(0 == lseek(fd, 0, SEEK_CUR));
  assert(0 == ftruncate(fd, 300));
  assert(0 == fstat(fd, &st));
  assert(st.st_size == 300);
  assert(0 == lseek(fd, 0, SEEK_CUR));
  assert(0 == close(fd));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    0x2e13(%rip),%rax
or     (%rax),%esi
lea    0xe4f(%rip),%rdi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1090 <fstat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpl   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edi
mov    $0x1f4,%esi
call   1040 <ftruncate@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1090 <fstat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpl   $0x1f4,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edi
mov    0x2d49(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edi
mov    $0x12c,%esi
call   1040 <ftruncate@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1090 <fstat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
cmpl   $0x12c,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edi
mov    0x2cca(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe80(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    0x2e59(%rip),%rax
mov    0x2e22(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe5c(%rip),%rdi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1070 <assert@plt>
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1090 <fstat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
cmpl   $0x0,0x8(%rsp)
sete   %dil
call   1070 <assert@plt>
mov    0x2de1(%rip),%r15
mov    (%r15),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %ebx,%edi
mov    $0x1f4,%esi
call   1040 <ftruncate@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1090 <fstat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
cmpl   $0x1f4,0x8(%rsp)
sete   %dil
call   1070 <assert@plt>
mov    (%r15),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %ebx,%edi
mov    $0x12c,%esi
call   1040 <ftruncate@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1090 <fstat@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %edi,%edi
cmpl   $0x12c,0x8(%rsp)
sete   %dil
call   1070 <assert@plt>
mov    (%r15),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.stat = type { 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_CUR = global i32 0
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i64 @mkdir(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 493)
%4 = icmp eq i64 %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 = call i64 @fstat(i32 %10, %struct.stat* %1)
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = load i32, i32* @SEEK_CUR
%24 = tail call i64 @lseek(i32 %10, i32 0, i32 %23)
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = tail call i64 @ftruncate(i32 %10, i32 500)
%29 = icmp eq i64 %28, 0
%30 = zext i1 %29 to i32
%31 = tail call i32 @assert(i32 %30)
%32 = call i64 @fstat(i32 %10, %struct.stat* %1)
%33 = icmp eq i64 %32, 0
%34 = zext i1 %33 to i32
%35 = tail call i32 @assert(i32 %34)
%36 = load i32, i32* %18
%37 = icmp eq i32 %36, 500
%38 = zext i1 %37 to i32
%39 = tail call i32 @assert(i32 %38)
%40 = load i32, i32* @SEEK_CUR
%41 = tail call i64 @lseek(i32 %10, i32 0, i32 %40)
%42 = icmp eq i64 %41, 0
%43 = zext i1 %42 to i32
%44 = tail call i32 @assert(i32 %43)
%45 = tail call i64 @ftruncate(i32 %10, i32 300)
%46 = icmp eq i64 %45, 0
%47 = zext i1 %46 to i32
%48 = tail call i32 @assert(i32 %47)
%49 = call i64 @fstat(i32 %10, %struct.stat* %1)
%50 = icmp eq i64 %49, 0
%51 = zext i1 %50 to i32
%52 = tail call i32 @assert(i32 %51)
%53 = load i32, i32* %18
%54 = icmp eq i32 %53, 300
%55 = zext i1 %54 to i32
%56 = tail call i32 @assert(i32 %55)
%57 = load i32, i32* @SEEK_CUR
%58 = tail call i64 @lseek(i32 %10, i32 0, i32 %57)
%59 = icmp eq i64 %58, 0
%60 = zext i1 %59 to i32
%61 = tail call i32 @assert(i32 %60)
%62 = tail call i64 @close(i32 %10)
%63 = icmp eq i64 %62, 0
%64 = zext i1 %63 to i32
%65 = tail call i32 @assert(i32 %64)
ret i32 0
}