#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 /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ pipe(int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  DIR *rootdir;
  DIR *tmpdir;
  int pipefds[2];
  int sock;
  rootdir = opendir("/");
  tmpdir = opendir(argv[1]);
  pipe(pipefds);
  sock = socket(AF_UNIX, SOCK_STREAM, 0);
  close(sock);
  close(pipefds[0]);
  close(pipefds[1]);
  closedir(rootdir);
  closedir(tmpdir);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
call   1050 <pipe@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%edi
call   1040 <close@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xea2(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
call   1050 <pipe@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%edi
call   1040 <close@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    %r14,%rdi
call   1060 <closedir@plt>
mov    %rbx,%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [2 x i32]
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @opendir(i8* %12)
store i32* %13, i32** %6
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%15 = call i32 @pipe(i32* %14)
%16 = load i32, i32* @AF_UNIX
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = call i32 @close(i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = load i32*, i32** %5
%28 = call i32 @closedir(i32* %27)
%29 = load i32*, i32** %6
%30 = call i32 @closedir(i32* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @opendir(i8* %7)
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = call i32 @close(i32 %13)
%15 = load i32, i32* %9
%16 = call i32 @close(i32 %15)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 @close(i32 %18)
%20 = call i32 @closedir(i32* %5)
%21 = call i32 @closedir(i32* %8)
ret i32 0
}