#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 */

/* Variables and functions */
int /*<<< orphan*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
scalar_t__ create_directory_for_user(char *);
scalar_t__ delete_log_directory(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
char *get_job_log_directory(char *);
scalar_t__ mkdirs(char *, int);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
void test_delete_log_directory() {
  printf("\nTesting delete_log_directory\n");
  char *job_log_dir = get_job_log_directory("job_1");
  if (job_log_dir == NULL) {
    exit(1);
  }
  if (create_directory_for_user(job_log_dir) != 0) {
    exit(1);
  }
  free(job_log_dir);
  char *task_log_dir = get_job_log_directory("job_1/task_2");
  if (task_log_dir == NULL) {
    exit(1);
  }
  if (mkdirs(task_log_dir, 0700) != 0) {
    exit(1);
  }
  if (access("/tmp/test-task-controller"
             "/logs/userlogs/job_1/task_2",
             R_OK) != 0) {
    printf("FAIL: can't access task directory - %s\n", strerror(errno));
    exit(1);
  }
  if (delete_log_directory("job_1/task_2") != 0) {
    printf("FAIL: can't delete task directory\n");
    exit(1);
  }
  if (access("/tmp/test-task-controller"
             "/logs/userlogs/job_1/task_2",
             R_OK) == 0) {
    printf("FAIL: task directory not deleted\n");
    exit(1);
  }
  if (access("/tmp/test-task-controller"
             "/logs/userlogs/job_1",
             R_OK) != 0) {
    printf("FAIL: job directory not deleted - %s\n", strerror(errno));
    exit(1);
  }
  if (delete_log_directory("job_1") != 0) {
    printf("FAIL: can't delete task directory\n");
    exit(1);
  }
  if (access("/tmp/test-task-controller"
             "/logs/userlogs/job_1",
             R_OK) == 0) {
    printf("FAIL: job directory not deleted\n");
    exit(1);
  }
  free(task_log_dir);
}


x86 assembly (clang, -O0):
<test_delete_log_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf3c(%rip),%rdi
call   10b0 <get_job_log_directory@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11cb <test_delete_log_directory+0x3b>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1060 <create_directory_for_user@plt>
cmp    $0x0,%rax
je     11e8 <test_delete_log_directory+0x58>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    0xe4f(%rip),%rdi
call   10b0 <get_job_log_directory@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1216 <test_delete_log_directory+0x86>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1c0,%esi
call   1080 <mkdirs@plt>
cmp    $0x0,%rax
je     1238 <test_delete_log_directory+0xa8>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
lea    0xdd7(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
je     1280 <test_delete_log_directory+0xf0>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdc0(%rip),%rdi
call   1050 <delete_log_directory@plt>
cmp    $0x0,%rax
je     12ae <test_delete_log_directory+0x11e>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%esi
lea    0xd61(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    12e5 <test_delete_log_directory+0x155>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%esi
lea    0xdcc(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
je     132d <test_delete_log_directory+0x19d>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdb5(%rip),%rdi
call   1050 <delete_log_directory@plt>
cmp    $0x0,%rax
je     135b <test_delete_log_directory+0x1cb>
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2c76(%rip),%rax
mov    (%rax),%esi
lea    0xd56(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
jne    1392 <test_delete_log_directory+0x202>
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_delete_log_directory>:
push   %r14
push   %rbx
push   %rax
lea    0xf06(%rip),%rdi
call   1040 <puts@plt>
lea    0xece(%rip),%rdi
call   10c0 <get_job_log_directory@plt>
test   %rax,%rax
je     129b <test_delete_log_directory+0xfb>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <create_directory_for_user@plt>
test   %rax,%rax
jne    129b <test_delete_log_directory+0xfb>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe40(%rip),%rdi
call   10c0 <get_job_log_directory@plt>
test   %rax,%rax
je     129b <test_delete_log_directory+0xfb>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1c0,%esi
call   1090 <mkdirs@plt>
test   %rax,%rax
jne    129b <test_delete_log_directory+0xfb>
mov    0x2dc2(%rip),%r14
mov    (%r14),%esi
lea    0xde0(%rip),%rdi
call   1080 <access@plt>
test   %rax,%rax
jne    12ae <test_delete_log_directory+0x10e>
lea    0xdf3(%rip),%rdi
call   1060 <delete_log_directory@plt>
test   %rax,%rax
jne    12a5 <test_delete_log_directory+0x105>
mov    (%r14),%esi
lea    0xdb7(%rip),%rdi
call   1080 <access@plt>
test   %rax,%rax
je     12c5 <test_delete_log_directory+0x125>
mov    (%r14),%esi
lea    0xe00(%rip),%rdi
call   1080 <access@plt>
test   %rax,%rax
jne    12ce <test_delete_log_directory+0x12e>
lea    0xe17(%rip),%rdi
call   1060 <delete_log_directory@plt>
test   %rax,%rax
jne    12a5 <test_delete_log_directory+0x105>
mov    (%r14),%esi
lea    0xddb(%rip),%rdi
call   1080 <access@plt>
test   %rax,%rax
je     12f7 <test_delete_log_directory+0x157>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe64(%rip),%rdi
jmp    12fe <test_delete_log_directory+0x15e>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd72(%rip),%rdi
jmp    12e3 <test_delete_log_directory+0x143>
lea    0xe23(%rip),%rdi
jmp    12fe <test_delete_log_directory+0x15e>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xda8(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdd1(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"\0ATesting delete_log_directory\0A\00"
@.str.1 = [6 x i8] c"job_1\00"
@.str.2 = [13 x i8] c"job_1/task_2\00"
@.str.3 = [53 x i8] c"/tmp/test-task-controller/logs/userlogs/job_1/task_2\00"
@R_OK = global i32 0
@.str.4 = [40 x i8] c"FAIL: can't access task directory - %s\0A\00"
@errno = global i32 0
@.str.5 = [35 x i8] c"FAIL: can't delete task directory\0A\00"
@.str.6 = [34 x i8] c"FAIL: task directory not deleted\0A\00"
@.str.7 = [46 x i8] c"/tmp/test-task-controller/logs/userlogs/job_1\00"
@.str.8 = [38 x i8] c"FAIL: job directory not deleted - %s\0A\00"
@.str.9 = [33 x i8] c"FAIL: job directory not deleted\0A\00"
define void @test_delete_log_directory() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%4 = call i8* @get_job_log_directory(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i8*, i8** %1
%11 = call i64 @create_directory_for_user(i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %9
%16 = load i8*, i8** %1
%17 = call i32 @free(i8* %16)
%18 = call i8* @get_job_log_directory(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i8* %18, i8** %2
%19 = load i8*, i8** %2
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %15
%24 = load i8*, i8** %2
%25 = call i64 @mkdirs(i8* %24, i32 448)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %23
%30 = load i32, i32* @R_OK
%31 = call i64 @access(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %29
%39 = call i64 @delete_log_directory(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %38
%45 = load i32, i32* @R_OK
%46 = call i64 @access(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %44
%52 = load i32, i32* @R_OK
%53 = call i64 @access(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %51
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %51
%61 = call i64 @delete_log_directory(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %60
%67 = load i32, i32* @R_OK
%68 = call i64 @access(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %67)
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %66
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %66
%74 = load i8*, i8** %2
%75 = call i32 @free(i8* %74)
ret void
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"job_1\00"
@.str.2 = [13 x i8] c"job_1/task_2\00"
@.str.3 = [53 x i8] c"/tmp/test-task-controller/logs/userlogs/job_1/task_2\00"
@R_OK = global i32 0
@.str.4 = [40 x i8] c"FAIL: can't access task directory - %s\0A\00"
@errno = global i32 0
@.str.7 = [46 x i8] c"/tmp/test-task-controller/logs/userlogs/job_1\00"
@.str.8 = [38 x i8] c"FAIL: job directory not deleted - %s\0A\00"
@str = [30 x i8] c"\0ATesting delete_log_directory\00"
@str.10 = [32 x i8] c"FAIL: job directory not deleted\00"
@str.12 = [33 x i8] c"FAIL: task directory not deleted\00"
@str.13 = [34 x i8] c"FAIL: can't delete task directory\00"
define void @test_delete_log_directory() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%2 = tail call i8* @get_job_log_directory(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i64 @create_directory_for_user(i8* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %6
%12 = tail call i32 @free(i8* %2)
%13 = tail call i8* @get_job_log_directory(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = tail call i64 @mkdirs(i8* %13, i32 448)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %17
%23 = load i32, i32* @R_OK
%24 = tail call i64 @access(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %22
%27 = load i32, i32* @errno
%28 = tail call i8* @strerror(i32 %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = tail call i64 @delete_log_directory(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.13, i64 0, i64 0))
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %31
%38 = load i32, i32* @R_OK
%39 = tail call i64 @access(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.12, i64 0, i64 0))
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %37
%45 = load i32, i32* @R_OK
%46 = tail call i64 @access(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %53, label %48
48: ; preds = %44
%49 = load i32, i32* @errno
%50 = tail call i8* @strerror(i32 %49)
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %50)
%52 = tail call i32 @exit(i32 1)
unreachable
53: ; preds = %44
%54 = tail call i64 @delete_log_directory(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.13, i64 0, i64 0))
%58 = tail call i32 @exit(i32 1)
unreachable
59: ; preds = %53
%60 = load i32, i32* @R_OK
%61 = tail call i64 @access(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0), i32 %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.10, i64 0, i64 0))
%65 = tail call i32 @exit(i32 1)
unreachable
66: ; preds = %59
%67 = tail call i32 @free(i8* %13)
ret void
}