#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*/ S_IFDIR;
int /*<<< orphan*/ S_IFREG;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ expect_type(char *, int /*<<< orphan*/);
int /*<<< orphan*/ mkdir_or_die(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int recursive_unlink_children(char *);
scalar_t__ rmdir(char *);
char *strerror(int);
int /*<<< orphan*/ symlink_or_die(char *, char *);
int /*<<< orphan*/ touch_or_die(char *);
scalar_t__ unlink(char *);
void test_recursive_unlink_children() {
  int ret;
  mkdir_or_die("/tmp/test-container-executor"
               "/unlinkRoot");
  mkdir_or_die("/tmp/test-container-executor"
               "/unlinkRoot/a");
  touch_or_die("/tmp/test-container-executor"
               "/unlinkRoot/b");
  mkdir_or_die("/tmp/test-container-executor"
               "/unlinkRoot/c");
  touch_or_die("/tmp/test-container-executor"
               "/unlinkRoot/c/d");
  touch_or_die("/tmp/test-container-executor"
               "/external");
  symlink_or_die("/tmp/test-container-executor"
                 "/external",
                 "/tmp/test-container-executor"
                 "/unlinkRoot/c/external");
  ret = recursive_unlink_children("/tmp/test-container-executor"
                                  "/unlinkRoot");
  if (ret != 0) {
    printf("recursive_unlink_children(%s) failed: error %d\n",
           "/tmp/test-container-executor"
           "/unlinkRoot",
           ret);
    exit(1);
  }
  expect_type("/tmp/test-container-executor"
              "/unlinkRoot",
              S_IFDIR);
  expect_type("/tmp/test-container-executor"
              "/unlinkRoot/a",
              0);
  expect_type("/tmp/test-container-executor"
              "/unlinkRoot/b",
              0);
  expect_type("/tmp/test-container-executor"
              "/unlinkRoot/c",
              0);
  expect_type("/tmp/test-container-executor"
              "/external",
              S_IFREG);
  if (rmdir("/tmp/test-container-executor"
            "/unlinkRoot") < 0) {
    int err = errno;
    printf("failed to rmdir "
           "/tmp/test-container-executor"
           "/unlinkRoot: %s\n",
           strerror(err));
  }
  if (unlink("/tmp/test-container-executor"
             "/external") < 0) {
    int err = errno;
    printf("failed to unlink "
           "/tmp/test-container-executor"
           "/external: %s\n",
           strerror(err));
  }
}


x86 assembly (clang, -O0):
<test_recursive_unlink_children>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe51(%rip),%rdi
call   10a0 <mkdir_or_die@plt>
lea    0xe6d(%rip),%rdi
call   10a0 <mkdir_or_die@plt>
lea    0xe8b(%rip),%rdi
call   1080 <touch_or_die@plt>
lea    0xea9(%rip),%rdi
call   10a0 <mkdir_or_die@plt>
lea    0xec7(%rip),%rdi
call   1080 <touch_or_die@plt>
lea    0xee7(%rip),%rdi
call   1080 <touch_or_die@plt>
lea    0xedb(%rip),%rdi
lea    0xefa(%rip),%rsi
call   1070 <symlink_or_die@plt>
lea    0xdf6(%rip),%rdi
call   1090 <recursive_unlink_children@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     123e <test_recursive_unlink_children+0x9e>
mov    -0x4(%rbp),%edx
lea    0xf05(%rip),%rdi
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
lea    0xdb2(%rip),%rdi
call   1050 <expect_type@plt>
lea    0xdce(%rip),%rdi
xor    %esi,%esi
call   1050 <expect_type@plt>
lea    0xdea(%rip),%rdi
xor    %esi,%esi
call   1050 <expect_type@plt>
lea    0xe06(%rip),%rdi
xor    %esi,%esi
call   1050 <expect_type@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    0xe45(%rip),%rdi
call   1050 <expect_type@plt>
lea    0xd67(%rip),%rdi
call   1040 <rmdir@plt>
cmp    $0x0,%rax
jge    12cd <test_recursive_unlink_children+0x12d>
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdfe(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    1308 <test_recursive_unlink_children+0x168>
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_recursive_unlink_children>:
push   %r14
push   %rbx
push   %rax
lea    0xe55(%rip),%r14
mov    %r14,%rdi
call   10a0 <mkdir_or_die@plt>
lea    0xe6e(%rip),%rdi
call   10a0 <mkdir_or_die@plt>
lea    0xe8c(%rip),%rdi
call   1080 <touch_or_die@plt>
lea    0xeaa(%rip),%rdi
call   10a0 <mkdir_or_die@plt>
lea    0xec8(%rip),%rdi
call   1080 <touch_or_die@plt>
lea    0xee8(%rip),%rbx
mov    %rbx,%rdi
call   1080 <touch_or_die@plt>
lea    0xeff(%rip),%rsi
mov    %rbx,%rdi
call   1070 <symlink_or_die@plt>
mov    %r14,%rdi
call   1090 <recursive_unlink_children@plt>
test   %eax,%eax
jne    12d3 <test_recursive_unlink_children+0x133>
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
lea    0xddf(%rip),%rbx
mov    %rbx,%rdi
call   1050 <expect_type@plt>
lea    0xdf8(%rip),%rdi
xor    %esi,%esi
call   1050 <expect_type@plt>
lea    0xe14(%rip),%rdi
xor    %esi,%esi
call   1050 <expect_type@plt>
lea    0xe30(%rip),%rdi
xor    %esi,%esi
call   1050 <expect_type@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1050 <expect_type@plt>
mov    %rbx,%rdi
call   1040 <rmdir@plt>
test   %rax,%rax
jns    1294 <test_recursive_unlink_children+0xf4>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xed1(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe37(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     12ad <test_recursive_unlink_children+0x10d>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xed6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <printf@plt>
lea    0xe51(%rip),%rdi
lea    0xd1f(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"/tmp/test-container-executor/unlinkRoot\00"
@.str.1 = [42 x i8] c"/tmp/test-container-executor/unlinkRoot/a\00"
@.str.2 = [42 x i8] c"/tmp/test-container-executor/unlinkRoot/b\00"
@.str.3 = [42 x i8] c"/tmp/test-container-executor/unlinkRoot/c\00"
@.str.4 = [44 x i8] c"/tmp/test-container-executor/unlinkRoot/c/d\00"
@.str.5 = [38 x i8] c"/tmp/test-container-executor/external\00"
@.str.6 = [51 x i8] c"/tmp/test-container-executor/unlinkRoot/c/external\00"
@.str.7 = [48 x i8] c"recursive_unlink_children(%s) failed: error %d\0A\00"
@S_IFDIR = global i32 0
@S_IFREG = global i32 0
@errno = global i32 0
@.str.8 = [61 x i8] c"failed to rmdir /tmp/test-container-executor/unlinkRoot: %s\0A\00"
@.str.9 = [60 x i8] c"failed to unlink /tmp/test-container-executor/external: %s\0A\00"
define void @test_recursive_unlink_children() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @mkdir_or_die(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @mkdir_or_die(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @touch_or_die(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @mkdir_or_die(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @touch_or_die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @touch_or_die(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
%10 = call i32 @symlink_or_die(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0))
%11 = call i32 @recursive_unlink_children(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = load i32, i32* %1
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = load i32, i32* @S_IFDIR
%20 = call i32 @expect_type(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32 @expect_type(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 0)
%22 = call i32 @expect_type(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 0)
%23 = call i32 @expect_type(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 0)
%24 = load i32, i32* @S_IFREG
%25 = call i32 @expect_type(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%26 = call i64 @rmdir(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %18
%29 = load i32, i32* @errno
store i32 %29, i32* %2
%30 = load i32, i32* %2
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.8, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28, %18
%34 = call i64 @unlink(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i32, i32* @errno
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.9, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %36, %33
ret void
}

LLVM IR (-O2):
@.str = [40 x i8] c"/tmp/test-container-executor/unlinkRoot\00"
@.str.1 = [42 x i8] c"/tmp/test-container-executor/unlinkRoot/a\00"
@.str.2 = [42 x i8] c"/tmp/test-container-executor/unlinkRoot/b\00"
@.str.3 = [42 x i8] c"/tmp/test-container-executor/unlinkRoot/c\00"
@.str.4 = [44 x i8] c"/tmp/test-container-executor/unlinkRoot/c/d\00"
@.str.5 = [38 x i8] c"/tmp/test-container-executor/external\00"
@.str.6 = [51 x i8] c"/tmp/test-container-executor/unlinkRoot/c/external\00"
@.str.7 = [48 x i8] c"recursive_unlink_children(%s) failed: error %d\0A\00"
@S_IFDIR = global i32 0
@S_IFREG = global i32 0
@errno = global i32 0
@.str.8 = [61 x i8] c"failed to rmdir /tmp/test-container-executor/unlinkRoot: %s\0A\00"
@.str.9 = [60 x i8] c"failed to unlink /tmp/test-container-executor/external: %s\0A\00"
define void @test_recursive_unlink_children() {
%1 = tail call i32 @mkdir_or_die(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @mkdir_or_die(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @touch_or_die(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 @mkdir_or_die(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%5 = tail call i32 @touch_or_die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%6 = tail call i32 @touch_or_die(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
%7 = tail call i32 @symlink_or_die(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0))
%8 = tail call i32 @recursive_unlink_children(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %8)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i32, i32* @S_IFDIR
%15 = tail call i32 @expect_type(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = tail call i32 @expect_type(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 0)
%17 = tail call i32 @expect_type(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 0)
%18 = tail call i32 @expect_type(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 0)
%19 = load i32, i32* @S_IFREG
%20 = tail call i32 @expect_type(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = tail call i64 @rmdir(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %13
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.8, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %23, %13
%28 = tail call i64 @unlink(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* @errno
%32 = tail call i8* @strerror(i32 %31)
%33 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.9, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %30, %27
ret void
}