#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 O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ chmod(char *, int);
int /*<<< orphan*/ chown(char *, int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fchmod(int, int);
int /*<<< orphan*/ fchown(int, int, int);
int /*<<< orphan*/ lchown(char *, int, int);
int open(char *, int, int);
int main() {
  int fd;
  fd = open("foobar", O_WRONLY | O_CREAT, 0666);
  chmod("foobar", 0644);
  fchmod(fd, 0444);
  chmod((char *)-1, 0644);
  fchmod(-1, 0644);
  chmod("foobar", -1);
  fchmod(fd, -1);
  chown((char *)-1, 5000, 5001);
  chown("foobar", 5000, -1);
  chown("foobar", -1, 5001);
  fchown(-1, 5002, 5003);
  fchown(fd, 5002, -1);
  fchown(fd, -1, 5003);
  lchown("foobar", 5004, -1);
  lchown("foobar", -1, 5005);
  lchown((char *)-1, 5005, 5006);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
mov    0x2e69(%rip),%rax
or     (%rax),%esi
lea    0xe68(%rip),%rdi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
lea    0xe54(%rip),%rdi
mov    $0x1a4,%esi
call   1070 <chmod@plt>
mov    -0x8(%rbp),%edi
mov    $0x124,%esi
call   1060 <fchmod@plt>
mov    $0xffffffffffffffff,%rdi
mov    $0x1a4,%esi
call   1070 <chmod@plt>
mov    $0xffffffff,%edi
mov    $0x1a4,%esi
call   1060 <fchmod@plt>
lea    0xe16(%rip),%rdi
mov    $0xffffffff,%esi
call   1070 <chmod@plt>
mov    -0x8(%rbp),%edi
mov    $0xffffffff,%esi
call   1060 <fchmod@plt>
mov    $0xffffffffffffffff,%rdi
mov    $0x1388,%esi
mov    $0x1389,%edx
call   1050 <chown@plt>
lea    0xde2(%rip),%rdi
mov    $0x1388,%esi
mov    $0xffffffff,%edx
call   1050 <chown@plt>
lea    0xdcc(%rip),%rdi
mov    $0xffffffff,%esi
mov    $0x1389,%edx
call   1050 <chown@plt>
mov    $0xffffffff,%edi
mov    $0x138a,%esi
mov    $0x138b,%edx
call   1090 <fchown@plt>
mov    -0x8(%rbp),%edi
mov    $0x138a,%esi
mov    $0xffffffff,%edx
call   1090 <fchown@plt>
mov    -0x8(%rbp),%edi
mov    $0xffffffff,%esi
mov    $0x138b,%edx
call   1090 <fchown@plt>
lea    0xd7e(%rip),%rdi
mov    $0x138c,%esi
mov    $0xffffffff,%edx
call   1040 <lchown@plt>
lea    0xd68(%rip),%rdi
mov    $0xffffffff,%esi
mov    $0x138d,%edx
call   1040 <lchown@plt>
mov    $0xffffffffffffffff,%rdi
mov    $0x138d,%esi
mov    $0x138e,%edx
call   1040 <lchown@plt>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e55(%rip),%rax
mov    0x2e76(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe73(%rip),%r14
mov    %r14,%rdi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0x1a4,%esi
call   1070 <chmod@plt>
mov    %ebx,%edi
mov    $0x124,%esi
call   1060 <fchmod@plt>
mov    $0xffffffffffffffff,%rdi
mov    $0x1a4,%esi
call   1070 <chmod@plt>
mov    $0xffffffff,%edi
mov    $0x1a4,%esi
call   1060 <fchmod@plt>
mov    %r14,%rdi
mov    $0xffffffff,%esi
call   1070 <chmod@plt>
mov    %ebx,%edi
mov    $0xffffffff,%esi
call   1060 <fchmod@plt>
mov    $0xffffffffffffffff,%rdi
mov    $0x1388,%esi
mov    $0x1389,%edx
call   1050 <chown@plt>
mov    %r14,%rdi
mov    $0x1388,%esi
mov    $0xffffffff,%edx
call   1050 <chown@plt>
mov    %r14,%rdi
mov    $0xffffffff,%esi
mov    $0x1389,%edx
call   1050 <chown@plt>
mov    $0xffffffff,%edi
mov    $0x138a,%esi
mov    $0x138b,%edx
call   1090 <fchown@plt>
mov    %ebx,%edi
mov    $0x138a,%esi
mov    $0xffffffff,%edx
call   1090 <fchown@plt>
mov    %ebx,%edi
mov    $0xffffffff,%esi
mov    $0x138b,%edx
call   1090 <fchown@plt>
mov    %r14,%rdi
mov    $0x138c,%esi
mov    $0xffffffff,%edx
call   1040 <lchown@plt>
mov    %r14,%rdi
mov    $0xffffffff,%esi
mov    $0x138d,%edx
call   1040 <lchown@plt>
mov    $0xffffffffffffffff,%rdi
mov    $0x138d,%esi
mov    $0x138e,%edx
call   1040 <lchown@plt>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"foobar\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_CREAT
%5 = or i32 %3, %4
%6 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5, i32 438)
store i32 %6, i32* %2
%7 = call i32 @chmod(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 420)
%8 = load i32, i32* %2
%9 = call i32 @fchmod(i32 %8, i32 292)
%10 = call i32 @chmod(i8* inttoptr (i64 -1 to i8*), i32 420)
%11 = call i32 @fchmod(i32 -1, i32 420)
%12 = call i32 @chmod(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1)
%13 = load i32, i32* %2
%14 = call i32 @fchmod(i32 %13, i32 -1)
%15 = call i32 @chown(i8* inttoptr (i64 -1 to i8*), i32 5000, i32 5001)
%16 = call i32 @chown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 5000, i32 -1)
%17 = call i32 @chown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1, i32 5001)
%18 = call i32 @fchown(i32 -1, i32 5002, i32 5003)
%19 = load i32, i32* %2
%20 = call i32 @fchown(i32 %19, i32 5002, i32 -1)
%21 = load i32, i32* %2
%22 = call i32 @fchown(i32 %21, i32 -1, i32 5003)
%23 = call i32 @lchown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 5004, i32 -1)
%24 = call i32 @lchown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1, i32 5005)
%25 = call i32 @lchown(i8* inttoptr (i64 -1 to i8*), i32 5005, i32 5006)
%26 = load i32, i32* %2
%27 = call i32 @close(i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"foobar\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_WRONLY
%2 = load i32, i32* @O_CREAT
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %3, i32 438)
%5 = tail call i32 @chmod(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 420)
%6 = tail call i32 @fchmod(i32 %4, i32 292)
%7 = tail call i32 @chmod(i8* inttoptr (i64 -1 to i8*), i32 420)
%8 = tail call i32 @fchmod(i32 -1, i32 420)
%9 = tail call i32 @chmod(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1)
%10 = tail call i32 @fchmod(i32 %4, i32 -1)
%11 = tail call i32 @chown(i8* inttoptr (i64 -1 to i8*), i32 5000, i32 5001)
%12 = tail call i32 @chown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 5000, i32 -1)
%13 = tail call i32 @chown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1, i32 5001)
%14 = tail call i32 @fchown(i32 -1, i32 5002, i32 5003)
%15 = tail call i32 @fchown(i32 %4, i32 5002, i32 -1)
%16 = tail call i32 @fchown(i32 %4, i32 -1, i32 5003)
%17 = tail call i32 @lchown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 5004, i32 -1)
%18 = tail call i32 @lchown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1, i32 5005)
%19 = tail call i32 @lchown(i8* inttoptr (i64 -1 to i8*), i32 5005, i32 5006)
%20 = tail call i32 @close(i32 %4)
ret i32 0
}