#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;
};
typedef int /*<<< orphan*/ err;

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
char *create_tempdir(char *, int, char *, size_t);
scalar_t__ expect(char *, char *, int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ recursive_unlink(char *);
int register_tempdir_for_cleanup(char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ unregister_tempdir_for_cleanup(char *);
int test_create_tempdir_and_delete(void) {
  char *tdir = NULL;
  struct stat st_buf;
  int ret;
  char err[128];
  size_t err_len = sizeof(err);
  tdir = create_tempdir("test_create_tempdir_and_delete", 0775, err, err_len);
  do {
    if (expect("",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/apache/incubator-htrace/refs/"
               "heads/master/htrace-c/src/test/temp_dir-unit.c"
               " at line "
               "62",
               0, "%s", err))
      return 1;
  } while (0);
  ;
  ;
  ret = register_tempdir_for_cleanup(tdir);
  if (ret)
    return EXIT_FAILURE;
  if (stat(tdir, &st_buf) == -1) {
    return EXIT_FAILURE;
  }
  if (!S_ISDIR(st_buf.st_mode)) {
    return EXIT_FAILURE;
  }
  recursive_unlink(tdir);
  unregister_tempdir_for_cleanup(tdir);
  free(tdir);
  return 0;
}


x86 assembly (clang, -O0):
<test_create_tempdir_and_delete>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x80,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
lea    0xe4d(%rip),%rdi
mov    $0x1fd,%esi
call   1090 <create_tempdir@plt>
mov    %rax,-0x10(%rbp)
lea    -0xa0(%rbp),%r8
lea    0xf00(%rip),%rdi
lea    0xe49(%rip),%rsi
xor    %edx,%edx
lea    0xef1(%rip),%rcx
call   1050 <expect@plt>
cmp    $0x0,%rax
je     11fa <test_create_tempdir_and_delete+0x7a>
movl   $0x1,-0x4(%rbp)
jmp    1291 <test_create_tempdir_and_delete+0x111>
jmp    11ff <test_create_tempdir_and_delete+0x7f>
mov    -0x10(%rbp),%rdi
call   1070 <register_tempdir_for_cleanup@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1226 <test_create_tempdir_and_delete+0xa6>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1291 <test_create_tempdir_and_delete+0x111>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    124d <test_create_tempdir_and_delete+0xcd>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1291 <test_create_tempdir_and_delete+0x111>
mov    -0x18(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    126f <test_create_tempdir_and_delete+0xef>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1291 <test_create_tempdir_and_delete+0x111>
mov    -0x10(%rbp),%rdi
call   10a0 <recursive_unlink@plt>
mov    -0x10(%rbp),%rdi
call   1040 <unregister_tempdir_for_cleanup@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_create_tempdir_and_delete>:
push   %r14
push   %rbx
sub    $0x98,%rsp
lea    0xe6f(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    $0x80,%ecx
mov    $0x1fd,%esi
mov    %rbx,%rdx
call   1090 <create_tempdir@plt>
mov    %rax,%r14
lea    0xf1d(%rip),%rdi
lea    0xe66(%rip),%rsi
lea    0xf10(%rip),%rcx
xor    %edx,%edx
mov    %rbx,%r8
call   1050 <expect@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11ec <test_create_tempdir_and_delete+0x6c>
mov    %r14,%rdi
call   1070 <register_tempdir_for_cleanup@plt>
test   %eax,%eax
je     11f7 <test_create_tempdir_and_delete+0x77>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
je     11e3 <test_create_tempdir_and_delete+0x63>
mov    0x8(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %eax,%eax
je     11e3 <test_create_tempdir_and_delete+0x63>
mov    %r14,%rdi
call   10a0 <recursive_unlink@plt>
mov    %r14,%rdi
call   1040 <unregister_tempdir_for_cleanup@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11ec <test_create_tempdir_and_delete+0x6c>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [31 x i8] c"test_create_tempdir_and_delete\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [177 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/apache/incubator-htrace/refs/heads/master/htrace-c/src/test/temp_dir-unit.c at line 62\00"
@.str.3 = [3 x i8] c"%s\00"
@EXIT_FAILURE = global i32 0
define i32 @test_create_tempdir_and_delete() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i32
%5 = alloca [128 x i8]
%6 = alloca i64
store i8* null, i8** %2
store i64 128, i64* %6
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = load i64, i64* %6
%9 = call i8* @create_tempdir(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 509, i8* %7, i64 %8)
store i8* %9, i8** %2
br label %10
10: ; preds = %0
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%12 = call i64 @expect(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 1, i32* %1
br label %43
15: ; preds = %10
br label %16
16: ; preds = %15
%17 = load i8*, i8** %2
%18 = call i32 @register_tempdir_for_cleanup(i8* %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %1
br label %43
23: ; preds = %16
%24 = load i8*, i8** %2
%25 = call i32 @stat(i8* %24, %struct.stat* %3)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %1
br label %43
29: ; preds = %23
%30 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @S_ISDIR(i32 %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %29
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %1
br label %43
36: ; preds = %29
%37 = load i8*, i8** %2
%38 = call i32 @recursive_unlink(i8* %37)
%39 = load i8*, i8** %2
%40 = call i32 @unregister_tempdir_for_cleanup(i8* %39)
%41 = load i8*, i8** %2
%42 = call i32 @free(i8* %41)
store i32 0, i32* %1
br label %43
43: ; preds = %36, %34, %27, %21, %14
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [31 x i8] c"test_create_tempdir_and_delete\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [177 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/apache/incubator-htrace/refs/heads/master/htrace-c/src/test/temp_dir-unit.c at line 62\00"
@.str.3 = [3 x i8] c"%s\00"
@EXIT_FAILURE = global i32 0
define i32 @test_create_tempdir_and_delete() {
%1 = alloca %struct.stat
%2 = alloca [128 x i8]
%3 = bitcast %struct.stat* %1 to i8*
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = call i8* @create_tempdir(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 509, i8* %4, i64 128)
%6 = call i64 @expect(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([177 x i8], [177 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %29
8: ; preds = %0
%9 = call i32 @register_tempdir_for_cleanup(i8* %5)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = load i32, i32* @EXIT_FAILURE
br label %29
13: ; preds = %8
%14 = call i32 @stat(i8* %5, %struct.stat* %1)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = load i32, i32* @EXIT_FAILURE
br label %29
18: ; preds = %13
%19 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @S_ISDIR(i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = load i32, i32* @EXIT_FAILURE
br label %29
25: ; preds = %18
%26 = call i32 @recursive_unlink(i8* %5)
%27 = call i32 @unregister_tempdir_for_cleanup(i8* %5)
%28 = call i32 @free(i8* %5)
br label %29
29: ; preds = %0, %25, %23, %16, %11
%30 = phi i32 [ %12, %11 ], [ %17, %16 ], [ 0, %25 ], [ %24, %23 ], [ 1, %0 ]
ret i32 %30
}