#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 check_user_perms(char *, char *);
int /*<<< orphan*/ eout(char *, ...);
int recursive_rm(char *);
int do_remove(char *JID) {
  int rc;
  rc = check_user_perms(JID, "JOB");
  if (rc == -2)
    rc = check_user_perms(JID, "JOB.error");
  if (rc == -2)
    rc = check_user_perms(JID, "JOB.suspended");
  if (rc == -2)
    rc = check_user_perms(JID, "JOB.done");
  if (rc < 0) {
    if (rc == -2)
      eout("no JOB file in %s/ - can't verify permissions\n", JID);
    return -1;
  }
  rc = recursive_rm(JID);
  if (rc < 0) {
    eout("could not remove %d files or subdirectories\n", -rc);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_remove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1040 <check_user_perms@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xfffffffe,-0x14(%rbp)
jne    116c <do_remove+0x3c>
mov    -0x10(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <check_user_perms@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xfffffffe,-0x14(%rbp)
jne    1189 <do_remove+0x59>
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <check_user_perms@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xfffffffe,-0x14(%rbp)
jne    11a6 <do_remove+0x76>
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1040 <check_user_perms@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d8 <do_remove+0xa8>
cmpl   $0xfffffffe,-0x14(%rbp)
jne    11cc <do_remove+0x9c>
mov    -0x10(%rbp),%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1050 <eout@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <do_remove+0xe4>
mov    -0x10(%rbp),%rdi
call   1030 <recursive_rm@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    120d <do_remove+0xdd>
xor    %esi,%esi
sub    -0x14(%rbp),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <eout@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <do_remove+0xe4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_remove>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec3(%rip),%rsi
call   1040 <check_user_perms@plt>
cmp    $0xfffffffe,%eax
jne    117e <do_remove+0x4e>
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
call   1040 <check_user_perms@plt>
cmp    $0xfffffffe,%eax
jne    117e <do_remove+0x4e>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
call   1040 <check_user_perms@plt>
cmp    $0xfffffffe,%eax
jne    117e <do_remove+0x4e>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
call   1040 <check_user_perms@plt>
test   %eax,%eax
js     11a9 <do_remove+0x79>
mov    %rbx,%rdi
call   1030 <recursive_rm@plt>
xor    %ebp,%ebp
test   %eax,%eax
jns    11c4 <do_remove+0x94>
neg    %eax
lea    0xebb(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <eout@plt>
mov    $0xffffffff,%ebp
jmp    11c4 <do_remove+0x94>
mov    $0xffffffff,%ebp
cmp    $0xfffffffe,%eax
jne    11c4 <do_remove+0x94>
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <eout@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"JOB\00"
@.str.1 = [10 x i8] c"JOB.error\00"
@.str.2 = [14 x i8] c"JOB.suspended\00"
@.str.3 = [9 x i8] c"JOB.done\00"
@.str.4 = [47 x i8] c"no JOB file in %s/ - can't verify permissions\0A\00"
@.str.5 = [45 x i8] c"could not remove %d files or subdirectories\0A\00"
define i32 @do_remove(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @check_user_perms(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, -2
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @check_user_perms(i8* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 %11, i32* %4
br label %12
12: ; preds = %9, %1
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, -2
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = call i32 @check_user_perms(i8* %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 %17, i32* %4
br label %18
18: ; preds = %15, %12
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, -2
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = call i32 @check_user_perms(i8* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 %23, i32* %4
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, -2
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i8*, i8** %3
%32 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %30, %27
store i32 -1, i32* %2
br label %44
34: ; preds = %24
%35 = load i8*, i8** %3
%36 = call i32 @recursive_rm(i8* %35)
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i32, i32* %4
%41 = sub nsw i32 0, %40
%42 = call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %41)
store i32 -1, i32* %2
br label %44
43: ; preds = %34
store i32 0, i32* %2
br label %44
44: ; preds = %43, %39, %33
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
@.str = [4 x i8] c"JOB\00"
@.str.1 = [10 x i8] c"JOB.error\00"
@.str.2 = [14 x i8] c"JOB.suspended\00"
@.str.3 = [9 x i8] c"JOB.done\00"
@.str.4 = [47 x i8] c"no JOB file in %s/ - can't verify permissions\0A\00"
@.str.5 = [45 x i8] c"could not remove %d files or subdirectories\0A\00"
define i32 @do_remove(i8* %0) {
%2 = tail call i32 @check_user_perms(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, -2
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = tail call i32 @check_user_perms(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %5, -2
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = tail call i32 @check_user_perms(i8* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32 %8, -2
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @check_user_perms(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %1, %4, %10, %7
%13 = phi i32 [ %11, %10 ], [ %8, %7 ], [ %5, %4 ], [ %2, %1 ]
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = icmp eq i32 %13, -2
br i1 %16, label %17, label %25
17: ; preds = %15
%18 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %25
19: ; preds = %12
%20 = tail call i32 @recursive_rm(i8* %0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = sub nsw i32 0, %20
%24 = tail call i32 (i8*, ...) @eout(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %19, %15, %17, %22
%26 = phi i32 [ -1, %22 ], [ -1, %17 ], [ -1, %15 ], [ 0, %19 ]
ret i32 %26
}