#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ privatise(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ stat(char *, struct stat *);
void main(int argc, char *argv[]) {
  struct stat buf;
  DIR *d;
  struct dirent *info;
  if (stat(argv[1], &buf) < 0) {
    perror("stat");
    exit(1);
  }
  if (S_ISDIR(buf.st_mode)) {
    chdir(argv[1]);
    d = opendir(".");
    while ((info = readdir(d)) != NULL)
      privatise(info->d_name);
  } else {
    privatise(argv[1]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jge    11c0 <main+0x40>
lea    0xe4f(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     121c <main+0x9c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
lea    0xe1f(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1217 <main+0x97>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1060 <privatise@plt>
jmp    11ef <main+0x6f>
jmp    1229 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <privatise@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
js     11f2 <main+0x72>
mov    0x8(%rsp),%edi
call   1050 <S_ISDIR@plt>
mov    0x8(%rbx),%rdi
test   %rax,%rax
je     11e7 <main+0x67>
call   1040 <chdir@plt>
lea    0xe4c(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1080 <readdir@plt>
test   %rax,%rax
je     11ec <main+0x6c>
mov    (%rax),%rdi
call   1060 <privatise@plt>
mov    %rbx,%rdi
jmp    11d0 <main+0x50>
call   1060 <privatise@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe07(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [5 x i8] c"stat\00"
@.str.1 = [2 x i8] c".\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.stat
%6 = alloca i32*
%7 = alloca %struct.dirent*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i8**, i8*** %4
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i64 @stat(i8* %10, %struct.stat* %5)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %16
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @chdir(i8* %24)
%26 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %6
br label %27
27: ; preds = %31, %21
%28 = load i32*, i32** %6
%29 = call %struct.dirent* @readdir(i32* %28)
store %struct.dirent* %29, %struct.dirent** %7
%30 = icmp ne %struct.dirent* %29, null
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load %struct.dirent*, %struct.dirent** %7
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 0
%34 = load i8*, i8** %33
%35 = call i32 @privatise(i8* %34)
br label %27
36: ; preds = %27
br label %42
37: ; preds = %16
%38 = load i8**, i8*** %4
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @privatise(i8* %40)
br label %42
42: ; preds = %37, %36
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [5 x i8] c"stat\00"
@.str.1 = [2 x i8] c".\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i64 @stat(i8* %6, %struct.stat* %3)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @S_ISDIR(i32 %14)
%16 = icmp eq i64 %15, 0
%17 = load i8*, i8** %5
br i1 %16, label %30, label %18
18: ; preds = %12
%19 = call i32 @chdir(i8* %17)
%20 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = call %struct.dirent* @readdir(i32* %20)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %32, label %23
23: ; preds = %18, %23
%24 = phi %struct.dirent* [ %28, %23 ], [ %21, %18 ]
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i64 0, i32 0
%26 = load i8*, i8** %25
%27 = call i32 @privatise(i8* %26)
%28 = call %struct.dirent* @readdir(i32* %20)
%29 = icmp eq %struct.dirent* %28, null
br i1 %29, label %32, label %23
30: ; preds = %12
%31 = call i32 @privatise(i8* %17)
br label %32
32: ; preds = %23, %18, %30
ret void
}