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

/* Variables and functions */
scalar_t__ chmod(char *, int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char *string_concat(int, char *, char *, int /*<<< orphan*/);
void recursiveChmod(char *path, mode_t mode) {
  if (chmod(path, mode))
    return;
  DIR *d = opendir(path);
  if (!d)
    return;
  struct dirent *ent;
  while ((ent = readdir(d)) != NULL) {
    if (strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0) {
      char *entPath = string_concat(3, path, "/", ent->d_name);
      recursiveChmod(entPath, mode);
      free(entPath);
    }
  }
  closedir(d);
}


x86 assembly (clang, -O0):
<recursiveChmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   10a0 <chmod@plt>
cmp    $0x0,%rax
je     11aa <recursiveChmod+0x2a>
jmp    125d <recursiveChmod+0xdd>
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c7 <recursiveChmod+0x47>
jmp    125d <recursiveChmod+0xdd>
jmp    11cc <recursiveChmod+0x4c>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1254 <recursiveChmod+0xd4>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     124f <recursiveChmod+0xcf>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     124f <recursiveChmod+0xcf>
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    $0x3,%edi
lea    0xdd2(%rip),%rdx
call   1090 <string_concat@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <recursiveChmod@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    11cc <recursiveChmod+0x4c>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursiveChmod>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r12
call   10a0 <chmod@plt>
test   %rax,%rax
je     11aa <recursiveChmod+0x2a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     119b <recursiveChmod+0x1b>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1246 <recursiveChmod+0xc6>
mov    %rax,%r13
lea    0xe30(%rip),%r15
jmp    11f0 <recursiveChmod+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1080 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     1246 <recursiveChmod+0xc6>
mov    0x0(%r13),%edi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11e0 <recursiveChmod+0x60>
mov    0x0(%r13),%edi
lea    0xdf4(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11e0 <recursiveChmod+0x60>
mov    0x0(%r13),%ecx
mov    $0x3,%edi
mov    %r12,%rsi
lea    0xdda(%rip),%rdx
call   1090 <string_concat@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14d,%esi
call   1040 <recursiveChmod@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11e0 <recursiveChmod+0x60>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <closedir@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
define void @recursiveChmod(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.dirent*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = load i32, i32* %4
%10 = call i64 @chmod(i8* %8, i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
br label %50
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i32* @opendir(i8* %14)
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %13
br label %50
19: ; preds = %13
br label %20
20: ; preds = %46, %19
%21 = load i32*, i32** %5
%22 = call %struct.dirent* @readdir(i32* %21)
store %struct.dirent* %22, %struct.dirent** %6
%23 = icmp ne %struct.dirent* %22, null
br i1 %23, label %24, label %47
24: ; preds = %20
%25 = load %struct.dirent*, %struct.dirent** %6
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i64 @strcmp(i32 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %46
30: ; preds = %24
%31 = load %struct.dirent*, %struct.dirent** %6
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i64 @strcmp(i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %30
%37 = load i8*, i8** %3
%38 = load %struct.dirent*, %struct.dirent** %6
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i8* @string_concat(i32 3, i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %40)
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = load i32, i32* %4
%44 = load i8*, i8** %7
%45 = call i32 @free(i8* %44)
br label %46
46: ; preds = %36, %30, %24
br label %20
47: ; preds = %20
%48 = load i32*, i32** %5
%49 = call i32 @closedir(i32* %48)
br label %50
50: ; preds = %47, %18, %12
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
define void @recursiveChmod(i8* %0, i32 %1) {
%3 = tail call i64 @chmod(i8* %0, i32 %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %30
5: ; preds = %2
%6 = tail call i32* @opendir(i8* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %30, label %8
8: ; preds = %5
%9 = tail call %struct.dirent* @readdir(i32* %6)
%10 = icmp eq %struct.dirent* %9, null
br i1 %10, label %28, label %11
11: ; preds = %8, %25
%12 = phi %struct.dirent* [ %26, %25 ], [ %9, %8 ]
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 0
%14 = load i32, i32* %13
%15 = tail call i64 @strcmp(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %11
%18 = load i32, i32* %13
%19 = tail call i64 @strcmp(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i32, i32* %13
%23 = tail call i8* @string_concat(i32 3, i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %22)
tail call void @recursiveChmod(i8* %23, i32 %1)
%24 = tail call i32 @free(i8* %23)
br label %25
25: ; preds = %21, %17, %11
%26 = tail call %struct.dirent* @readdir(i32* %6)
%27 = icmp eq %struct.dirent* %26, null
br i1 %27, label %28, label %11
28: ; preds = %25, %8
%29 = tail call i32 @closedir(i32* %6)
br label %30
30: ; preds = %28, %5, %2
ret void
}