#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 S_IREAD;
int S_IWRITE;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ ftruncate(int, int);
int /*<<< orphan*/ truncate(char *, int);
int main() {
  int fd;
  fd = creat("foobar", S_IREAD | S_IWRITE);
  ftruncate(fd, 1024);
  ftruncate(-1, 1024);
  ftruncate(fd, -1);
  close(fd);
  truncate("foobar", 2048);
  truncate((char *)-1, 2048);
  truncate("foobar", -1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    0x2e89(%rip),%rax
or     (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <creat@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x400,%esi
call   1030 <ftruncate@plt>
mov    $0xffffffff,%edi
mov    $0x400,%esi
call   1030 <ftruncate@plt>
mov    -0x8(%rbp),%edi
mov    $0xffffffff,%esi
call   1030 <ftruncate@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    0xe58(%rip),%rdi
mov    $0x800,%esi
call   1050 <truncate@plt>
mov    $0xffffffffffffffff,%rdi
mov    $0x800,%esi
call   1050 <truncate@plt>
lea    0xe36(%rip),%rdi
mov    $0xffffffff,%esi
call   1050 <truncate@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    0x2e97(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xea4(%rip),%rbx
mov    %rbx,%rdi
call   1060 <creat@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x400,%esi
call   1030 <ftruncate@plt>
mov    $0xffffffff,%edi
mov    $0x400,%esi
call   1030 <ftruncate@plt>
mov    %ebp,%edi
mov    $0xffffffff,%esi
call   1030 <ftruncate@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %rbx,%rdi
mov    $0x800,%esi
call   1050 <truncate@plt>
mov    $0xffffffffffffffff,%rdi
mov    $0x800,%esi
call   1050 <truncate@plt>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1050 <truncate@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"foobar\00"
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @S_IREAD
%4 = load i32, i32* @S_IWRITE
%5 = or i32 %3, %4
%6 = call i32 @creat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @ftruncate(i32 %7, i32 1024)
%9 = call i32 @ftruncate(i32 -1, i32 1024)
%10 = load i32, i32* %2
%11 = call i32 @ftruncate(i32 %10, i32 -1)
%12 = load i32, i32* %2
%13 = call i32 @close(i32 %12)
%14 = call i32 @truncate(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 2048)
%15 = call i32 @truncate(i8* inttoptr (i64 -1 to i8*), i32 2048)
%16 = call i32 @truncate(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"foobar\00"
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
define i32 @main() {
%1 = load i32, i32* @S_IREAD
%2 = load i32, i32* @S_IWRITE
%3 = or i32 %2, %1
%4 = tail call i32 @creat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @ftruncate(i32 %4, i32 1024)
%6 = tail call i32 @ftruncate(i32 -1, i32 1024)
%7 = tail call i32 @ftruncate(i32 %4, i32 -1)
%8 = tail call i32 @close(i32 %4)
%9 = tail call i32 @truncate(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 2048)
%10 = tail call i32 @truncate(i8* inttoptr (i64 -1 to i8*), i32 2048)
%11 = tail call i32 @truncate(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1)
ret i32 0
}