#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 register_tempdir_for_cleanup(char *);
int stat(char *, struct stat *);
int test_create_tempdir(void) {
  char *tdir = NULL;
  struct stat st_buf;
  char err[128];
  size_t err_len = sizeof(err);
  int ret;
  tdir = create_tempdir("test_create_tempdir", 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 "
               "38",
               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;
  }
  free(tdir);
  return 0;
}


x86 assembly (clang, -O0):
<test_create_tempdir>:
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    0xe6d(%rip),%rdi
mov    $0x1fd,%esi
call   1080 <create_tempdir@plt>
mov    %rax,-0x10(%rbp)
lea    -0xa0(%rbp),%r8
lea    0xf15(%rip),%rdi
lea    0xe5e(%rip),%rsi
xor    %edx,%edx
lea    0xf06(%rip),%rcx
call   1040 <expect@plt>
cmp    $0x0,%rax
je     11da <test_create_tempdir+0x7a>
movl   $0x1,-0x4(%rbp)
jmp    1265 <test_create_tempdir+0x105>
jmp    11df <test_create_tempdir+0x7f>
mov    -0x10(%rbp),%rdi
call   1060 <register_tempdir_for_cleanup@plt>
mov    %eax,-0xac(%rbp)
cmpl   $0x0,-0xac(%rbp)
je     120c <test_create_tempdir+0xac>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1265 <test_create_tempdir+0x105>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    1233 <test_create_tempdir+0xd3>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1265 <test_create_tempdir+0x105>
mov    -0x18(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1255 <test_create_tempdir+0xf5>
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1265 <test_create_tempdir+0x105>
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>:
push   %r14
push   %rbx
sub    $0x98,%rsp
lea    0xe8f(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    $0x80,%ecx
mov    $0x1fd,%esi
mov    %rbx,%rdx
call   1080 <create_tempdir@plt>
mov    %rax,%r14
lea    0xf32(%rip),%rdi
lea    0xe7b(%rip),%rsi
lea    0xf25(%rip),%rcx
xor    %edx,%edx
mov    %rbx,%r8
call   1040 <expect@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11cc <test_create_tempdir+0x6c>
mov    %r14,%rdi
call   1060 <register_tempdir_for_cleanup@plt>
test   %eax,%eax
je     11d7 <test_create_tempdir+0x77>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
je     11c3 <test_create_tempdir+0x63>
mov    0x8(%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %eax,%eax
je     11c3 <test_create_tempdir+0x63>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11cc <test_create_tempdir+0x6c>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [20 x i8] c"test_create_tempdir\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 38\00"
@.str.3 = [3 x i8] c"%s\00"
@EXIT_FAILURE = global i32 0
define i32 @test_create_tempdir() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca [128 x i8]
%5 = alloca i64
%6 = alloca i32
store i8* null, i8** %2
store i64 128, i64* %5
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = load i64, i64* %5
%9 = call i8* @create_tempdir(i8* getelementptr inbounds ([20 x i8], [20 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]* %4, 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 %39
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* %6
%19 = load i32, i32* %6
%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 %39
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 %39
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 %39
36: ; preds = %29
%37 = load i8*, i8** %2
%38 = call i32 @free(i8* %37)
store i32 0, i32* %1
br label %39
39: ; preds = %36, %34, %27, %21, %14
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [20 x i8] c"test_create_tempdir\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 38\00"
@.str.3 = [3 x i8] c"%s\00"
@EXIT_FAILURE = global i32 0
define i32 @test_create_tempdir() {
%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 ([20 x i8], [20 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 %27
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 %27
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 %27
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 %27
25: ; preds = %18
%26 = call i32 @free(i8* %5)
br label %27
27: ; preds = %0, %25, %23, %16, %11
%28 = phi i32 [ %12, %11 ], [ %17, %16 ], [ 0, %25 ], [ %24, %23 ], [ 1, %0 ]
ret i32 %28
}