#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 */
scalar_t__ cg_check_frozen(char *, int);
scalar_t__ cg_create(char *);
scalar_t__ cg_destroy(char *);
scalar_t__ cg_freeze_wait(char *, int);
char *cg_name(char const *, char *);
int /*<<< orphan*/ free(char *);
int test_cgfreezer_rmdir(const char *root) {
  int ret = 1;
  char *parent, *child = NULL;
  parent = cg_name(root, "cg_test_rmdir_A");
  if (!parent)
    goto cleanup;
  child = cg_name(parent, "cg_test_rmdir_B");
  if (!child)
    goto cleanup;
  if (cg_create(parent))
    goto cleanup;
  if (cg_create(child))
    goto cleanup;
  if (cg_freeze_wait(parent, true))
    goto cleanup;
  if (cg_destroy(child))
    goto cleanup;
  if (cg_check_frozen(parent, true))
    goto cleanup;
  if (cg_create(child))
    goto cleanup;
  if (cg_check_frozen(child, true))
    goto cleanup;
  ret = 0;
cleanup:
  if (child)
    cg_destroy(child);
  free(child);
  if (parent)
    cg_destroy(parent);
  free(parent);
  return ret;
}


x86 assembly (clang, -O0):
<test_cgfreezer_rmdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119f <test_cgfreezer_rmdir+0x3f>
jmp    1281 <test_cgfreezer_rmdir+0x121>
mov    -0x18(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c3 <test_cgfreezer_rmdir+0x63>
jmp    1281 <test_cgfreezer_rmdir+0x121>
mov    -0x18(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     11db <test_cgfreezer_rmdir+0x7b>
jmp    1281 <test_cgfreezer_rmdir+0x121>
mov    -0x20(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     11f3 <test_cgfreezer_rmdir+0x93>
jmp    1281 <test_cgfreezer_rmdir+0x121>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1070 <cg_freeze_wait@plt>
cmp    $0x0,%rax
je     1210 <test_cgfreezer_rmdir+0xb0>
jmp    1281 <test_cgfreezer_rmdir+0x121>
mov    -0x20(%rbp),%rdi
call   1030 <cg_destroy@plt>
cmp    $0x0,%rax
je     1228 <test_cgfreezer_rmdir+0xc8>
jmp    1281 <test_cgfreezer_rmdir+0x121>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1080 <cg_check_frozen@plt>
cmp    $0x0,%rax
je     1245 <test_cgfreezer_rmdir+0xe5>
jmp    1281 <test_cgfreezer_rmdir+0x121>
mov    -0x20(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     125d <test_cgfreezer_rmdir+0xfd>
jmp    1281 <test_cgfreezer_rmdir+0x121>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1080 <cg_check_frozen@plt>
cmp    $0x0,%rax
je     127a <test_cgfreezer_rmdir+0x11a>
jmp    1281 <test_cgfreezer_rmdir+0x121>
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1295 <test_cgfreezer_rmdir+0x135>
mov    -0x20(%rbp),%rdi
call   1030 <cg_destroy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
cmpq   $0x0,-0x18(%rbp)
je     12b2 <test_cgfreezer_rmdir+0x152>
mov    -0x18(%rbp),%rdi
call   1030 <cg_destroy@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_cgfreezer_rmdir>:
push   %rbp
push   %r14
push   %rbx
lea    0xe95(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,%rbx
test   %rax,%rax
je     121e <test_cgfreezer_rmdir+0xbe>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <cg_name@plt>
mov    %rax,%r14
test   %rax,%rax
je     122c <test_cgfreezer_rmdir+0xcc>
mov    %rbx,%rdi
call   1060 <cg_create@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1214 <test_cgfreezer_rmdir+0xb4>
mov    %r14,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    1214 <test_cgfreezer_rmdir+0xb4>
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <cg_freeze_wait@plt>
test   %rax,%rax
jne    1214 <test_cgfreezer_rmdir+0xb4>
mov    %r14,%rdi
call   1030 <cg_destroy@plt>
test   %rax,%rax
jne    1214 <test_cgfreezer_rmdir+0xb4>
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
call   1080 <cg_check_frozen@plt>
test   %rax,%rax
jne    1214 <test_cgfreezer_rmdir+0xb4>
mov    %r14,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    1214 <test_cgfreezer_rmdir+0xb4>
mov    %r14,%rdi
mov    $0x1,%esi
call   1080 <cg_check_frozen@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %r14,%rdi
call   1030 <cg_destroy@plt>
jmp    1231 <test_cgfreezer_rmdir+0xd1>
xor    %edi,%edi
call   1040 <free@plt>
mov    $0x1,%ebp
jmp    1241 <test_cgfreezer_rmdir+0xe1>
mov    $0x1,%ebp
mov    %r14,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1030 <cg_destroy@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"cg_test_rmdir_A\00"
@.str.1 = [16 x i8] c"cg_test_rmdir_B\00"
define i32 @test_cgfreezer_rmdir(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i32 1, i32* %3
store i8* null, i8** %5
%6 = load i8*, i8** %2
%7 = call i8* @cg_name(i8* %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
br label %53
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i8* @cg_name(i8* %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %11
br label %53
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = call i64 @cg_create(i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
br label %53
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = call i64 @cg_create(i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
br label %53
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = call i64 @cg_freeze_wait(i8* %28, i32 1)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
br label %53
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = call i64 @cg_destroy(i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
br label %53
37: ; preds = %32
%38 = load i8*, i8** %4
%39 = call i64 @cg_check_frozen(i8* %38, i32 1)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
br label %53
42: ; preds = %37
%43 = load i8*, i8** %5
%44 = call i64 @cg_create(i8* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
br label %53
47: ; preds = %42
%48 = load i8*, i8** %5
%49 = call i64 @cg_check_frozen(i8* %48, i32 1)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %47
br label %53
52: ; preds = %47
store i32 0, i32* %3
br label %53
53: ; preds = %52, %51, %46, %41, %36, %31, %26, %21, %16, %10
%54 = load i8*, i8** %5
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i8*, i8** %5
%58 = call i64 @cg_destroy(i8* %57)
br label %59
59: ; preds = %56, %53
%60 = load i8*, i8** %5
%61 = call i32 @free(i8* %60)
%62 = load i8*, i8** %4
%63 = icmp ne i8* %62, null
br i1 %63, label %64, label %67
64: ; preds = %59
%65 = load i8*, i8** %4
%66 = call i64 @cg_destroy(i8* %65)
br label %67
67: ; preds = %64, %59
%68 = load i8*, i8** %4
%69 = call i32 @free(i8* %68)
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@.str = [16 x i8] c"cg_test_rmdir_A\00"
@.str.1 = [16 x i8] c"cg_test_rmdir_B\00"
define i32 @test_cgfreezer_rmdir(i8* %0) {
%2 = tail call i8* @cg_name(i8* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %32, label %4
4: ; preds = %1
%5 = tail call i8* @cg_name(i8* %2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %34, label %7
7: ; preds = %4
%8 = tail call i64 @cg_create(i8* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %29
10: ; preds = %7
%11 = tail call i64 @cg_create(i8* %5)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = tail call i64 @cg_freeze_wait(i8* %2, i32 1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = tail call i64 @cg_destroy(i8* %5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = tail call i64 @cg_check_frozen(i8* %2, i32 1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = tail call i64 @cg_create(i8* %5)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = tail call i64 @cg_check_frozen(i8* %5, i32 1)
%27 = icmp ne i64 %26, 0
%28 = zext i1 %27 to i32
br label %29
29: ; preds = %7, %10, %13, %16, %19, %22, %25
%30 = phi i32 [ %28, %25 ], [ 1, %22 ], [ 1, %19 ], [ 1, %16 ], [ 1, %13 ], [ 1, %10 ], [ 1, %7 ]
%31 = tail call i64 @cg_destroy(i8* %5)
br label %34
32: ; preds = %1
%33 = tail call i32 @free(i8* null)
br label %38
34: ; preds = %4, %29
%35 = phi i32 [ 1, %4 ], [ %30, %29 ]
%36 = tail call i32 @free(i8* %5)
%37 = tail call i64 @cg_destroy(i8* %2)
br label %38
38: ; preds = %32, %34
%39 = phi i32 [ %35, %34 ], [ 1, %32 ]
%40 = tail call i32 @free(i8* %2)
ret i32 %39
}