#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);
  chown("foobar", 5000, -1);
  chown("foobar", -1, 5001);
  fchown(fd, 5002, -1);
  fchown(fd, -1, 5003);
  lchown("foobar", 5004, -1);
  lchown("foobar", -1, 5005);
  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>
lea    0xe36(%rip),%rdi
mov    $0x1388,%esi
mov    $0xffffffff,%edx
call   1050 <chown@plt>
lea    0xe20(%rip),%rdi
mov    $0xffffffff,%esi
mov    $0x1389,%edx
call   1050 <chown@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    0xde6(%rip),%rdi
mov    $0x138c,%esi
mov    $0xffffffff,%edx
call   1040 <lchown@plt>
lea    0xdd0(%rip),%rdi
mov    $0xffffffff,%esi
mov    $0x138d,%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   %rbp
push   %rbx
push   %rax
mov    0x2e56(%rip),%rax
mov    0x2e77(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe74(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   1070 <chmod@plt>
mov    %ebp,%edi
mov    $0x124,%esi
call   1060 <fchmod@plt>
mov    %rbx,%rdi
mov    $0x1388,%esi
mov    $0xffffffff,%edx
call   1050 <chown@plt>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
mov    $0x1389,%edx
call   1050 <chown@plt>
mov    %ebp,%edi
mov    $0x138a,%esi
mov    $0xffffffff,%edx
call   1090 <fchown@plt>
mov    %ebp,%edi
mov    $0xffffffff,%esi
mov    $0x138b,%edx
call   1090 <fchown@plt>
mov    %rbx,%rdi
mov    $0x138c,%esi
mov    $0xffffffff,%edx
call   1040 <lchown@plt>
mov    %rbx,%rdi
mov    $0xffffffff,%esi
mov    $0x138d,%edx
call   1040 <lchown@plt>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
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 @chown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 5000, i32 -1)
%11 = call i32 @chown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1, i32 5001)
%12 = load i32, i32* %2
%13 = call i32 @fchown(i32 %12, i32 5002, i32 -1)
%14 = load i32, i32* %2
%15 = call i32 @fchown(i32 %14, i32 -1, i32 5003)
%16 = call i32 @lchown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 5004, i32 -1)
%17 = call i32 @lchown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1, i32 5005)
%18 = load i32, i32* %2
%19 = call i32 @close(i32 %18)
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 @chown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 5000, i32 -1)
%8 = tail call i32 @chown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1, i32 5001)
%9 = tail call i32 @fchown(i32 %4, i32 5002, i32 -1)
%10 = tail call i32 @fchown(i32 %4, i32 -1, i32 5003)
%11 = tail call i32 @lchown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 5004, i32 -1)
%12 = tail call i32 @lchown(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 -1, i32 5005)
%13 = tail call i32 @close(i32 %4)
ret i32 0
}