#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int errno;
int /*<<< orphan*/ fstat(int, struct stat *);
int ftruncate(int, int);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stat(char *, struct stat *);
int truncate(char *, int);
int main() {
  struct stat s;
  int f = open("/towrite", O_WRONLY);
  int f2 = open("/toread", O_RDONLY);
  printf("f2: %d\n", f2);
  fstat(f, &s);
  printf("st_size: %d\n", s.st_size);
  memset(&s, 0, sizeof s);
  errno = 0;
  printf("\n");
  printf("ftruncate(10): %d\n", ftruncate(f, 10));
  printf("errno: %d\n", errno);
  fstat(f, &s);
  printf("st_size: %d\n", s.st_size);
  memset(&s, 0, sizeof s);
  errno = 0;
  printf("\n");
  printf("ftruncate(4): %d\n", ftruncate(f, 4));
  printf("errno: %d\n", errno);
  fstat(f, &s);
  printf("st_size: %d\n", s.st_size);
  memset(&s, 0, sizeof s);
  errno = 0;
  printf("\n");
  printf("ftruncate(-1): %d\n", ftruncate(f, -1));
  printf("errno: %d\n", errno);
  fstat(f, &s);
  printf("st_size: %d\n", s.st_size);
  memset(&s, 0, sizeof s);
  errno = 0;
  printf("\n");
  printf("truncate(2): %d\n", truncate("/towrite", 2));
  printf("errno: %d\n", errno);
  stat("/towrite", &s);
  printf("st_size: %d\n", s.st_size);
  memset(&s, 0, sizeof s);
  errno = 0;
  printf("\n");
  printf("truncate(readonly, 2): %d\n", truncate("/toread", 2));
  printf("errno: %d\n", errno);
  stat("/toread", &s);
  printf("st_size: %d\n", s.st_size);
  memset(&s, 0, sizeof s);
  errno = 0;
  printf("\n");
  printf("ftruncate(readonly, 4): %d\n", ftruncate(f2, 4));
  printf("errno: %d\n", errno);
  fstat(f2, &s);
  printf("st_size: %d\n", s.st_size);
  memset(&s, 0, sizeof s);
  errno = 0;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1090 <fstat@plt>
mov    -0x8(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2de4(%rip),%rax
movl   $0x0,(%rax)
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    $0xa,%esi
call   1040 <ftruncate@plt>
mov    %eax,%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1090 <fstat@plt>
mov    -0x8(%rbp),%esi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2d68(%rip),%rax
movl   $0x0,(%rax)
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    $0x4,%esi
call   1040 <ftruncate@plt>
mov    %eax,%esi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1090 <fstat@plt>
mov    -0x8(%rbp),%esi
lea    0xd4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2cec(%rip),%rax
movl   $0x0,(%rax)
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    $0xffffffff,%esi
call   1040 <ftruncate@plt>
mov    %eax,%esi
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%esi
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1090 <fstat@plt>
mov    -0x8(%rbp),%esi
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2c70(%rip),%rax
movl   $0x0,(%rax)
lea    0xcc2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xc7d(%rip),%rdi
mov    $0x2,%esi
call   1070 <truncate@plt>
mov    %eax,%esi
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2c34(%rip),%rax
mov    (%rax),%esi
lea    0xc8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xc45(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <stat@plt>
mov    -0x8(%rbp),%esi
lea    0xc4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2bec(%rip),%rax
movl   $0x0,(%rax)
lea    0xc3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xc02(%rip),%rdi
mov    $0x2,%esi
call   1070 <truncate@plt>
mov    %eax,%esi
lea    0xc60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2bb0(%rip),%rax
mov    (%rax),%esi
lea    0xc08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xbca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <stat@plt>
mov    -0x8(%rbp),%esi
lea    0xbc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2b68(%rip),%rax
movl   $0x0,(%rax)
lea    0xbba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%edi
mov    $0x4,%esi
call   1040 <ftruncate@plt>
mov    %eax,%esi
lea    0xbfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2b30(%rip),%rax
mov    (%rax),%esi
lea    0xb88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1090 <fstat@plt>
mov    -0x8(%rbp),%esi
lea    0xb4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2aec(%rip),%rax
movl   $0x0,(%rax)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rbp
mov    %rbp,%rdi
call   1090 <open@plt>
mov    %eax,%r15d
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe53(%rip),%rdi
call   1090 <open@plt>
mov    %eax,0x4(%rsp)
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %r15d,%edi
mov    %rbx,%rsi
call   10a0 <fstat@plt>
mov    (%rsp),%esi
lea    0xe32(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    0x2dd1(%rip),%r13
movl   $0x0,0x0(%r13)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15d,%edi
mov    $0xa,%esi
call   1050 <ftruncate@plt>
lea    0xdf9(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
lea    0xdf8(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   10a0 <fstat@plt>
mov    (%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
movl   $0x0,0x0(%r13)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15d,%edi
mov    $0x4,%esi
call   1050 <ftruncate@plt>
lea    0xdac(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   10a0 <fstat@plt>
mov    (%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
movl   $0x0,0x0(%r13)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15d,%edi
mov    $0xffffffff,%esi
call   1050 <ftruncate@plt>
lea    0xd5a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   10a0 <fstat@plt>
mov    (%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
movl   $0x0,0x0(%r13)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbp,%rdi
mov    $0x2,%esi
call   1080 <truncate@plt>
lea    0xd09(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <stat@plt>
mov    (%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
movl   $0x0,0x0(%r13)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xc52(%rip),%rbp
mov    %rbp,%rdi
mov    $0x2,%esi
call   1080 <truncate@plt>
lea    0xcaf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <stat@plt>
mov    (%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
movl   $0x0,0x0(%r13)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%ebp
mov    %ebp,%edi
mov    $0x4,%esi
call   1050 <ftruncate@plt>
lea    0xc63(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   10a0 <fstat@plt>
mov    (%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
movl   $0x0,0x0(%r13)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [9 x i8] c"/towrite\00"
@O_WRONLY = global i32 0
@.str.1 = [8 x i8] c"/toread\00"
@O_RDONLY = global i32 0
@.str.2 = [8 x i8] c"f2: %d\0A\00"
@.str.3 = [13 x i8] c"st_size: %d\0A\00"
@errno = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [19 x i8] c"ftruncate(10): %d\0A\00"
@.str.6 = [11 x i8] c"errno: %d\0A\00"
@.str.7 = [18 x i8] c"ftruncate(4): %d\0A\00"
@.str.8 = [19 x i8] c"ftruncate(-1): %d\0A\00"
@.str.9 = [17 x i8] c"truncate(2): %d\0A\00"
@.str.10 = [27 x i8] c"truncate(readonly, 2): %d\0A\00"
@.str.11 = [28 x i8] c"ftruncate(readonly, 4): %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %3
%12 = call i32 @fstat(i32 %11, %struct.stat* %2)
%13 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
store i32 0, i32* @errno
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%18 = load i32, i32* %3
%19 = call i32 @ftruncate(i32 %18, i32 10)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @errno
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %3
%24 = call i32 @fstat(i32 %23, %struct.stat* %2)
%25 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
store i32 0, i32* @errno
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32, i32* %3
%31 = call i32 @ftruncate(i32 %30, i32 4)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %31)
%33 = load i32, i32* @errno
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %3
%36 = call i32 @fstat(i32 %35, %struct.stat* %2)
%37 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
store i32 0, i32* @errno
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%42 = load i32, i32* %3
%43 = call i32 @ftruncate(i32 %42, i32 -1)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %43)
%45 = load i32, i32* @errno
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %3
%48 = call i32 @fstat(i32 %47, %struct.stat* %2)
%49 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
store i32 0, i32* @errno
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @truncate(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 2)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %54)
%56 = load i32, i32* @errno
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %56)
%58 = call i32 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%59 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %60)
%62 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
store i32 0, i32* @errno
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%64 = call i32 @truncate(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 2)
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %64)
%66 = load i32, i32* @errno
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %66)
%68 = call i32 @stat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %2)
%69 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%70 = load i32, i32* %69
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %70)
%72 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
store i32 0, i32* @errno
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32, i32* %4
%75 = call i32 @ftruncate(i32 %74, i32 4)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0), i32 %75)
%77 = load i32, i32* @errno
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %77)
%79 = load i32, i32* %4
%80 = call i32 @fstat(i32 %79, %struct.stat* %2)
%81 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%82 = load i32, i32* %81
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %82)
%84 = call i32 @memset(%struct.stat* %2, i32 0, i32 4)
store i32 0, i32* @errno
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [9 x i8] c"/towrite\00"
@O_WRONLY = global i32 0
@.str.1 = [8 x i8] c"/toread\00"
@O_RDONLY = global i32 0
@.str.2 = [8 x i8] c"f2: %d\0A\00"
@.str.3 = [13 x i8] c"st_size: %d\0A\00"
@errno = global i32 0
@.str.5 = [19 x i8] c"ftruncate(10): %d\0A\00"
@.str.6 = [11 x i8] c"errno: %d\0A\00"
@.str.7 = [18 x i8] c"ftruncate(4): %d\0A\00"
@.str.8 = [19 x i8] c"ftruncate(-1): %d\0A\00"
@.str.9 = [17 x i8] c"truncate(2): %d\0A\00"
@.str.10 = [27 x i8] c"truncate(readonly, 2): %d\0A\00"
@.str.11 = [28 x i8] c"ftruncate(readonly, 4): %d\0A\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = call i32 @fstat(i32 %4, %struct.stat* %1)
%9 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = call i32 @memset(%struct.stat* %1, i32 0, i32 4)
store i32 0, i32* @errno
%13 = call i32 @putchar(i32 10)
%14 = call i32 @ftruncate(i32 %4, i32 10)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @errno
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %16)
%18 = call i32 @fstat(i32 %4, %struct.stat* %1)
%19 = load i32, i32* %9
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = call i32 @memset(%struct.stat* %1, i32 0, i32 4)
store i32 0, i32* @errno
%22 = call i32 @putchar(i32 10)
%23 = call i32 @ftruncate(i32 %4, i32 4)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @errno
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%27 = call i32 @fstat(i32 %4, %struct.stat* %1)
%28 = load i32, i32* %9
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = call i32 @memset(%struct.stat* %1, i32 0, i32 4)
store i32 0, i32* @errno
%31 = call i32 @putchar(i32 10)
%32 = call i32 @ftruncate(i32 %4, i32 -1)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %32)
%34 = load i32, i32* @errno
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %34)
%36 = call i32 @fstat(i32 %4, %struct.stat* %1)
%37 = load i32, i32* %9
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = call i32 @memset(%struct.stat* %1, i32 0, i32 4)
store i32 0, i32* @errno
%40 = call i32 @putchar(i32 10)
%41 = call i32 @truncate(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 2)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %41)
%43 = load i32, i32* @errno
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %43)
%45 = call i32 @stat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%46 = load i32, i32* %9
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = call i32 @memset(%struct.stat* %1, i32 0, i32 4)
store i32 0, i32* @errno
%49 = call i32 @putchar(i32 10)
%50 = call i32 @truncate(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 2)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %50)
%52 = load i32, i32* @errno
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %52)
%54 = call i32 @stat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %1)
%55 = load i32, i32* %9
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %55)
%57 = call i32 @memset(%struct.stat* %1, i32 0, i32 4)
store i32 0, i32* @errno
%58 = call i32 @putchar(i32 10)
%59 = call i32 @ftruncate(i32 %6, i32 4)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0), i32 %59)
%61 = load i32, i32* @errno
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %61)
%63 = call i32 @fstat(i32 %6, %struct.stat* %1)
%64 = load i32, i32* %9
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %64)
%66 = call i32 @memset(%struct.stat* %1, i32 0, i32 4)
store i32 0, i32* @errno
ret i32 0
}