#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*/ PATH_MAX;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int system(char *);
void rmtree(char *topdir) {
  char command[PATH_MAX + 10];
  int status;
  sprintf(command, "rm -rf %s", topdir);
  status = system(command);
  if (status < 0) {
    perror("system");
    exit(1);
  } else if (status != 0) {
    fprintf(stderr, "'%s' failed\n", command);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<rmtree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
add    $0xa,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdx
lea    0xe6a(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11c7 <rmtree+0x77>
lea    0xe52(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11f4 <rmtree+0xa4>
mov    -0x28(%rbp),%rdx
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11f9 <rmtree+0xa9>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmtree>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    %rdi,%rdx
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
add    $0xa,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
test   %eax,%eax
js     119a <rmtree+0x4a>
jne    11b0 <rmtree+0x60>
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe69(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [10 x i8] c"rm -rf %s\00"
@.str.1 = [7 x i8] c"system\00"
@stderr = global i32 0
@.str.2 = [13 x i8] c"'%s' failed\0A\00"
define void @rmtree(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i32, i32* @PATH_MAX
%7 = add nsw i32 %6, 10
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
%11 = load i8*, i8** %2
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @system(i8* %10)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %1
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
br label %27
27: ; preds = %26
%28 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [10 x i8] c"rm -rf %s\00"
@.str.1 = [7 x i8] c"system\00"
@stderr = global i32 0
@.str.2 = [13 x i8] c"'%s' failed\0A\00"
define void @rmtree(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = add nsw i32 %2, 10
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32 @system(i8* %5)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = icmp eq i32 %7, 0
br i1 %13, label %18, label %14
14: ; preds = %12
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
ret void
}