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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int deleteR(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ errno;
char *getenv(char *);
char *malloc(size_t);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
int rmdir(char *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *, char const *);
char *strerror(int /*<<< orphan*/);
int strlen(char const *);
int main(int argc, char *argv[]) {
  (void)argc;
  (void)argv;
  char *home = getenv("HOME");
  if (home == NULL) {
    printf("error 0: Set the environment HOME to the home directory\n");
    return 1;
  }
  const char *trashcan = "/.trashcan";
  size_t bufsize = strlen(home) + strlen(trashcan) + 1;
  char *trashdir = malloc(bufsize);
  snprintf(trashdir, bufsize, "%s%s", home, trashcan);
  DIR *d = opendir(trashdir);
  if (d == NULL) {
    printf("error: %s\n", strerror(errno));
    return 1;
  }
  int err = deleteR(d, trashdir);
  closedir(d);
  if (err == -1) {
    return 1;
  }
  if (rmdir(trashdir) == -1) {
    printf("error: %s\n", strerror(errno));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe43(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11eb <main+0x4b>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fa <main+0x15a>
lea    0xe4c(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xe0a(%rip),%rdx
call   1090 <snprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1287 <main+0xe7>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fa <main+0x15a>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <deleteR@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   10a0 <closedir@plt>
cmpl   $0xffffffff,-0x3c(%rbp)
jne    12b6 <main+0x116>
movl   $0x1,-0x4(%rbp)
jmp    12fa <main+0x15a>
mov    -0x30(%rbp),%rdi
call   1060 <rmdir@plt>
cmp    $0xffffffff,%eax
jne    12f3 <main+0x153>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fa <main+0x15a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe41(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1277 <main+0xc7>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <strlen@plt>
mov    %eax,%r14d
lea    0xe23(%rip),%r15
mov    %r15,%rdi
call   1080 <strlen@plt>
add    %r14d,%eax
add    $0x1,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   10c0 <malloc@plt>
mov    %rax,%r14
lea    0xe0b(%rip),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rcx
mov    %r15,%r8
call   10a0 <snprintf@plt>
mov    %r14,%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     1256 <main+0xa6>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <deleteR@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   10b0 <closedir@plt>
mov    $0x1,%eax
cmp    $0xffffffff,%ebp
je     1288 <main+0xd8>
mov    %r14,%rdi
call   1070 <rmdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1288 <main+0xd8>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xdaa(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    1283 <main+0xd3>
lea    0xda2(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [57 x i8] c"error 0: Set the environment HOME to the home directory\0A\00"
@.str.2 = [11 x i8] c"/.trashcan\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [11 x i8] c"error: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %60
19: ; preds = %2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %7
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
%22 = load i8*, i8** %7
%23 = call i32 @strlen(i8* %22)
%24 = add nsw i32 %21, %23
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
store i64 %26, i64* %8
%27 = load i64, i64* %8
%28 = call i8* @malloc(i64 %27)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
%30 = load i64, i64* %8
%31 = load i8*, i8** %6
%32 = load i8*, i8** %7
%33 = call i32 @snprintf(i8* %29, i64 %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %31, i8* %32)
%34 = load i8*, i8** %9
%35 = call i32* @opendir(i8* %34)
store i32* %35, i32** %10
%36 = load i32*, i32** %10
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %42
38: ; preds = %19
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %40)
store i32 1, i32* %3
br label %60
42: ; preds = %19
%43 = load i32*, i32** %10
%44 = load i8*, i8** %9
%45 = call i32 @deleteR(i32* %43, i8* %44)
store i32 %45, i32* %11
%46 = load i32*, i32** %10
%47 = call i32 @closedir(i32* %46)
%48 = load i32, i32* %11
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %51
50: ; preds = %42
store i32 1, i32* %3
br label %60
51: ; preds = %42
%52 = load i8*, i8** %9
%53 = call i32 @rmdir(i8* %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %57)
store i32 1, i32* %3
br label %60
59: ; preds = %51
store i32 0, i32* %3
br label %60
60: ; preds = %59, %55, %50, %38, %17
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.2 = [11 x i8] c"/.trashcan\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [11 x i8] c"error: %s\0A\00"
@errno = global i32 0
@str = [56 x i8] c"error 0: Set the environment HOME to the home directory\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
br label %32
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %3)
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%10 = add i32 %8, 1
%11 = add i32 %10, %9
%12 = sext i32 %11 to i64
%13 = tail call i8* @malloc(i64 %12)
%14 = tail call i32 @snprintf(i8* %13, i64 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32* @opendir(i8* %13)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %7
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %19)
br label %32
21: ; preds = %7
%22 = tail call i32 @deleteR(i32* %15, i8* %13)
%23 = tail call i32 @closedir(i32* %15)
%24 = icmp eq i32 %22, -1
br i1 %24, label %32, label %25
25: ; preds = %21
%26 = tail call i32 @rmdir(i8* %13)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %17, %25, %21, %28, %5
%33 = phi i32 [ 1, %5 ], [ 1, %17 ], [ 1, %28 ], [ 1, %21 ], [ 0, %25 ]
ret i32 %33
}