#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int unlink(char *);
int unlink_recursive(char *);
int usage();
int rm_main(int argc, char *argv[]) {
  int ret;
  int i = 1;
  int recursive = 0;
  if (argc < 2)
    return usage();
  if (argc >= 2 && (!strcmp(argv[1], "-r") || !strcmp(argv[1], "-R"))) {
    recursive = 1;
    i = 2;
  }
  for (; i < argc; i++) {
    int ret = recursive ? unlink_recursive(argv[i]) : unlink(argv[i]);
    if (ret < 0) {
      fprintf(stderr, "rm failed for %s, %s\n", argv[i], strerror(errno));
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<rm_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1196 <rm_main+0x36>
mov    $0x0,%al
call   1070 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12a6 <rm_main+0x146>
cmpl   $0x2,-0x8(%rbp)
jl     11e8 <rm_main+0x88>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11da <rm_main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe37(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11e8 <rm_main+0x88>
movl   $0x1,-0x1c(%rbp)
movl   $0x2,-0x18(%rbp)
jmp    11ed <rm_main+0x8d>
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    129f <rm_main+0x13f>
cmpl   $0x0,-0x1c(%rbp)
je     121c <rm_main+0xbc>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <unlink_recursive@plt>
mov    %eax,-0x24(%rbp)
jmp    1230 <rm_main+0xd0>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    128c <rm_main+0x12c>
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xd8b(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a6 <rm_main+0x146>
jmp    1291 <rm_main+0x131>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ed <rm_main+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_main>:
cmp    $0x1,%edi
jg     116c <rm_main+0xc>
xor    %eax,%eax
jmp    1070 <usage@plt>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%r15d
mov    0x8(%rsi),%r14
lea    0xe78(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11b1 <rm_main+0x51>
lea    0xe68(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11b1 <rm_main+0x51>
mov    $0x1,%r13b
mov    $0x1,%eax
jmp    11b9 <rm_main+0x59>
mov    $0x2,%eax
xor    %r13d,%r13d
xor    %r14d,%r14d
cmp    %r15d,%eax
jae    123b <rm_main+0xdb>
mov    %eax,%ebx
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    (%r12,%rbx,8),%rdi
test   %r13b,%r13b
je     11f0 <rm_main+0x90>
call   1030 <unlink@plt>
test   %eax,%eax
jns    11f9 <rm_main+0x99>
jmp    1204 <rm_main+0xa4>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1040 <unlink_recursive@plt>
test   %eax,%eax
js     1204 <rm_main+0xa4>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11d0 <rm_main+0x70>
jmp    123b <rm_main+0xdb>
mov    0x2dd5(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%eax
mov    (%r12,%rax,8),%rbx
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdde(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-r\00"
@.str.1 = [3 x i8] c"-R\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"rm failed for %s, %s\0A\00"
@errno = global i32 0
define i32 @rm_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 0, i32* %8
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @usage()
store i32 %13, i32* %3
br label %71
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp sge i32 %15, 2
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %23, %17
store i32 1, i32* %8
store i32 2, i32* %7
br label %30
30: ; preds = %29, %23, %14
br label %31
31: ; preds = %67, %30
%32 = load i32, i32* %7
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %70
35: ; preds = %31
%36 = load i32, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %35
%39 = load i8**, i8*** %5
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 @unlink_recursive(i8* %43)
br label %52
45: ; preds = %35
%46 = load i8**, i8*** %5
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
%50 = load i8*, i8** %49
%51 = call i32 @unlink(i8* %50)
br label %52
52: ; preds = %45, %38
%53 = phi i32 [ %44, %38 ], [ %51, %45 ]
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %66
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = load i8**, i8*** %5
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
%62 = load i8*, i8** %61
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %62, i8* %64)
store i32 -1, i32* %3
br label %71
66: ; preds = %52
br label %67
67: ; preds = %66
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
br label %31
70: ; preds = %31
store i32 0, i32* %3
br label %71
71: ; preds = %70, %56, %12
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@.str = [3 x i8] c"-r\00"
@.str.1 = [3 x i8] c"-R\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"rm failed for %s, %s\0A\00"
@errno = global i32 0
define i32 @rm_main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %44
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11, %6
br label %15
15: ; preds = %14, %11
%16 = phi i32 [ 1, %11 ], [ 2, %14 ]
%17 = phi i1 [ true, %11 ], [ false, %14 ]
%18 = icmp ult i32 %16, %0
br i1 %18, label %19, label %44
19: ; preds = %15
%20 = zext i32 %16 to i64
%21 = zext i32 %0 to i64
br label %22
22: ; preds = %19, %41
%23 = phi i64 [ %20, %19 ], [ %42, %41 ]
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
br i1 %17, label %28, label %26
26: ; preds = %22
%27 = tail call i32 @unlink_recursive(i8* %25)
br label %30
28: ; preds = %22
%29 = tail call i32 @unlink(i8* %25)
br label %30
30: ; preds = %28, %26
%31 = phi i32 [ %27, %26 ], [ %29, %28 ]
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = and i64 %23, 4294967295
%36 = getelementptr inbounds i8*, i8** %1, i64 %35
%37 = load i8*, i8** %36
%38 = load i32, i32* @errno
%39 = tail call i8* @strerror(i32 %38)
%40 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %39)
br label %44
41: ; preds = %30
%42 = add nuw nsw i64 %23, 1
%43 = icmp eq i64 %42, %21
br i1 %43, label %44, label %22
44: ; preds = %41, %15, %33, %4
%45 = phi i32 [ %5, %4 ], [ -1, %33 ], [ 0, %15 ], [ 0, %41 ]
ret i32 %45
}