#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getgid();
int getpid();
int getuid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ smash_it(char *, int /*<<< orphan*/);
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int time(int /*<<< orphan*/);
int mysrm(char *file) {
  int result;
  srand((getpid() + getuid() + getgid()) ^ time(0));
  char rmfile[strlen(file) + 1];
  strcpy(rmfile, file);
  if ((strcmp("/", rmfile) == 0) || (strcmp(".", rmfile) == 0) ||
      (strcmp("..", rmfile) == 0)) {
    printf("DANGEREOUS target!\n");
    exit(1);
  }
  result = (int)smash_it(rmfile, 0);
  switch (result) {
  case 0:
    return 0;
  case 1:
    fprintf(stderr, "Error: File %s - ", rmfile);
    perror("");
    break;
  case -1:
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<mysrm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,-0x44(%rbp)
mov    %al,-0x45(%rbp)
call   1050 <getpid@plt>
mov    %eax,%ecx
mov    -0x45(%rbp),%al
mov    %ecx,-0x4c(%rbp)
call   1070 <getuid@plt>
mov    -0x4c(%rbp),%ecx
mov    %eax,%edx
mov    -0x45(%rbp),%al
add    %edx,%ecx
mov    %ecx,-0x40(%rbp)
call   10d0 <getgid@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x3c(%rbp)
call   10c0 <time@plt>
mov    -0x3c(%rbp),%edi
xor    %eax,%edi
call   1090 <srand@plt>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rsi
lea    0xd99(%rip),%rdi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     12aa <mysrm+0xda>
mov    -0x38(%rbp),%rsi
lea    0xd82(%rip),%rdi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     12aa <mysrm+0xda>
mov    -0x38(%rbp),%rsi
lea    0xd67(%rip),%rdi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    12c0 <mysrm+0xf0>
lea    0xd54(%rip),%rdi
call   1080 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1040 <smash_it@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x50(%rbp)
sub    $0xffffffff,%eax
je     1340 <mysrm+0x170>
jmp    12e2 <mysrm+0x112>
mov    -0x50(%rbp),%eax
test   %eax,%eax
je     1303 <mysrm+0x133>
jmp    12f2 <mysrm+0x122>
mov    -0x50(%rbp),%eax
sub    $0x1,%eax
je     1316 <mysrm+0x146>
jmp    1345 <mysrm+0x175>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1353 <mysrm+0x183>
mov    -0x38(%rbp),%rdx
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
lea    0xcef(%rip),%rsi
call   10b0 <fprintf@plt>
lea    0xce2(%rip),%rdi
call   10e0 <perror@plt>
jmp    1345 <mysrm+0x175>
jmp    1345 <mysrm+0x175>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mysrm>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <getuid@plt>
add    %eax,%ebx
xor    %eax,%eax
call   10d0 <getgid@plt>
add    %eax,%ebx
xor    %edi,%edi
call   10c0 <time@plt>
xor    %eax,%ebx
mov    %ebx,%edi
call   1090 <srand@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xdcd(%rip),%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12a8 <mysrm+0xd8>
lea    0xdbc(%rip),%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12a8 <mysrm+0xd8>
lea    0xda7(%rip),%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12a8 <mysrm+0xd8>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <smash_it@plt>
cmp    $0x1,%eax
je     1282 <mysrm+0xb2>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    0xd73(%rip),%rsi
mov    %rbx,%rdx
call   10b0 <fprintf@plt>
lea    0xd75(%rip),%rdi
call   10e0 <perror@plt>
jmp    1277 <mysrm+0xa7>
lea    0xd68(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [20 x i8] c"DANGEREOUS target!\0A\00"
@stderr = global i32 0
@.str.4 = [18 x i8] c"Error: File %s - \00"
@.str.5 = [1 x i8] zeroinitializer
define i32 @mysrm(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
%8 = call i32 (...) @getpid()
%9 = call i32 (...) @getuid()
%10 = add nsw i32 %8, %9
%11 = call i32 (...) @getgid()
%12 = add nsw i32 %10, %11
%13 = call i32 @time(i32 0)
%14 = xor i32 %12, %13
%15 = call i32 @srand(i32 %14)
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, 1
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %5
%21 = alloca i8, i64 %19
store i64 %19, i64* %6
%22 = load i8*, i8** %3
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %21)
%25 = icmp eq i64 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %1
%27 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29, %26, %1
%33 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %29
%36 = call i64 @smash_it(i8* %21, i32 0)
%37 = trunc i64 %36 to i32
store i32 %37, i32* %4
%38 = load i32, i32* %4
switch i32 %38, label %45 [
i32 0, label %39
i32 1, label %40
i32 -1, label %44
]
39: ; preds = %35
store i32 0, i32* %2
store i32 1, i32* %7
br label %46
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%43 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
br label %45
44: ; preds = %35
br label %45
45: ; preds = %35, %44, %40
store i32 0, i32* %2
store i32 1, i32* %7
br label %46
46: ; preds = %45, %39
%47 = load i8*, i8** %5
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@stderr = global i32 0
@.str.4 = [18 x i8] c"Error: File %s - \00"
@.str.5 = [1 x i8] zeroinitializer
@str = [19 x i8] c"DANGEREOUS target!\00"
define i32 @mysrm(i8* %0) {
%2 = tail call i32 (...) @getpid()
%3 = tail call i32 (...) @getuid()
%4 = add nsw i32 %3, %2
%5 = tail call i32 (...) @getgid()
%6 = add nsw i32 %4, %5
%7 = tail call i32 @time(i32 0)
%8 = xor i32 %6, %7
%9 = tail call i32 @srand(i32 %8)
%10 = tail call i32 @strlen(i8* %0)
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = alloca i8, i64 %12
%14 = call i32 @strcpy(i8* %13, i8* %0)
%15 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %13)
%16 = icmp eq i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %1
%18 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20, %17, %1
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = call i64 @smash_it(i8* %13, i32 0)
%28 = trunc i64 %27 to i32
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%33 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %26, %30
ret i32 0
}