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

/* Variables and functions */
int /*<<< orphan*/ _IO(float, int);
int dirfd(int /*<<< orphan*/ *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int main(int argc, char *argv[]) {
  char cwd[1024];
  int fd;
  DIR *d;
  if (getcwd(cwd, sizeof(cwd)) != NULL) {
    d = opendir(cwd);
    fd = dirfd(d);
    ioctl(fd, _IO('f', 22));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1060 <getcwd@plt>
cmp    $0x0,%rax
je     11d4 <main+0x84>
lea    -0x410(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rdi
call   1070 <dirfd@plt>
mov    %eax,-0x414(%rbp)
mov    -0x414(%rbp),%eax
mov    %eax,-0x424(%rbp)
movss  0xe43(%rip),%xmm0
mov    $0x16,%edi
call   1040 <_IO@plt>
mov    -0x424(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    %rsp,%rdi
mov    $0x400,%esi
call   1060 <getcwd@plt>
test   %rax,%rax
je     1197 <main+0x47>
mov    %rsp,%rdi
call   1030 <opendir@plt>
mov    %rax,%rdi
call   1070 <dirfd@plt>
mov    %eax,%ebx
movss  0xe7c(%rip),%xmm0
mov    $0x16,%edi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = call i32* @getcwd(i8* %9, i32 1024)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = call i32* @opendir(i8* %13)
store i32* %14, i32** %8
%15 = load i32*, i32** %8
%16 = call i32 @dirfd(i32* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = call i32 @_IO(float 1.020000e+02, i32 22)
%19 = call i32 @ioctl(i32 %17, i32 %18)
br label %20
20: ; preds = %12, %2
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32* @getcwd(i8* %4, i32 1024)
%6 = icmp eq i32* %5, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = call i32* @opendir(i8* %4)
%9 = call i32 @dirfd(i32* %8)
%10 = call i32 @_IO(float 1.020000e+02, i32 22)
%11 = call i32 @ioctl(i32 %9, i32 %10)
br label %12
12: ; preds = %7, %2
ret i32 0
}