#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 */
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int dirfd(int /*<<< orphan*/ *);
scalar_t__ fchmodat(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int main(void) {
  DIR *dot = opendir(".");
  if (NULL == dot)
    return EXIT_FAILURE;
  int dfd = dirfd(dot);
  if (-1 == dfd)
    return EXIT_FAILURE;
  if (0 > fchmodat(dfd, "arnold.layne", 0000, 0))
    return EXIT_FAILURE;
  else
    return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    116c <main+0x3c>
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d5 <main+0xa5>
mov    -0x10(%rbp),%rdi
call   1040 <dirfd@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1197 <main+0x67>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d5 <main+0xa5>
mov    -0x14(%rbp),%edi
lea    0xe61(%rip),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <fchmodat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    11c9 <main+0x99>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11d5 <main+0xa5>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1030 <opendir@plt>
mov    0x2e9c(%rip),%rbx
test   %rax,%rax
je     117d <main+0x4d>
mov    %rax,%rdi
call   1040 <dirfd@plt>
cmp    $0xffffffff,%eax
je     117d <main+0x4d>
lea    0xea5(%rip),%rsi
mov    %eax,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <fchmodat@plt>
test   %rax,%rax
jns    1176 <main+0x46>
mov    0x2e6c(%rip),%rbx
jmp    117d <main+0x4d>
mov    0x2e5b(%rip),%rbx
mov    (%rbx),%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"arnold.layne\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* null, %5
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = load i32, i32* @EXIT_FAILURE
store i32 %8, i32* %1
br label %24
9: ; preds = %0
%10 = load i32*, i32** %2
%11 = call i32 @dirfd(i32* %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 -1, %12
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %1
br label %24
16: ; preds = %9
%17 = load i32, i32* %3
%18 = call i64 @fchmodat(i32 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0)
%19 = icmp sgt i64 0, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %1
br label %24
22: ; preds = %16
%23 = load i32, i32* @EXIT_SUCCESS
store i32 %23, i32* %1
br label %24
24: ; preds = %22, %20, %14, %7
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"arnold.layne\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i32 @dirfd(i32* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i64 @fchmodat(i32 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 0)
%8 = icmp slt i64 %7, 0
%9 = select i1 %8, i32* @EXIT_FAILURE, i32* @EXIT_SUCCESS
br label %10
10: ; preds = %3, %6, %0
%11 = phi i32* [ @EXIT_FAILURE, %0 ], [ @EXIT_FAILURE, %3 ], [ %9, %6 ]
%12 = load i32, i32* %11
ret i32 %12
}