#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*/ command;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ execvp(char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ isalnum(char const);
int rand();
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, const char **argv) {
  if (argc != 2) {
    fprintf(stderr, "usage: rich-core-helper report_label\n");
    return EXIT_FAILURE;
  }
  const char *label = argv[1];
  size_t label_len = strlen(label);
  if (label_len == 0) {
    goto invalid_label;
  }
  size_t i;
  for (i = 0; i != label_len; ++i) {
    if (!isalnum(label[i]) && !label[i] == '_' && !label[i] == '-') {
      goto invalid_label;
    }
  }
  srand(time(NULL));
  int randomid = rand();
  char command[128];
  snprintf(command, sizeof(command),
           "/usr/sbin/rich-core-dumper --name=%s --signal=%d", label, randomid);
  setuid(0);
  char *args[] = {"/bin/env", "-i", "/bin/bash", "-c", command, NULL};
  if (execvp(args[0], args)) {
    fprintf(stderr, "Couldn't invoke rich-core-dumper\n");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
invalid_label:
  fprintf(stderr, "Invalid crash report label: %s\n", label);
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11db <main+0x4b>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139c <main+0x20c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1204 <main+0x74>
jmp    1375 <main+0x1e5>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     128d <main+0xfd>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    1277 <main+0xe7>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x5f,%eax
jne    1277 <main+0xe7>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x2d,%eax
jne    1277 <main+0xe7>
jmp    1375 <main+0x1e5>
jmp    127c <main+0xec>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    120c <main+0x7c>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    %eax,-0x2c(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
mov    $0x80,%esi
lea    0xd64(%rip),%rdx
call   1050 <snprintf@plt>
xor    %edi,%edi
call   10a0 <setuid@plt>
lea    0xd82(%rip),%rax
mov    %rax,-0xe0(%rbp)
lea    0xd7d(%rip),%rax
mov    %rax,-0xd8(%rbp)
lea    0xd72(%rip),%rax
mov    %rax,-0xd0(%rbp)
lea    0xd6e(%rip),%rax
mov    %rax,-0xc8(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xc0(%rbp)
movq   $0x0,-0xb8(%rbp)
mov    -0xe0(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1090 <execvp@plt>
cmp    $0x0,%rax
je     1364 <main+0x1d4>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139c <main+0x20c>
mov    0x2c65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    139c <main+0x20c>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd09(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xb0,%rsp
cmp    $0x2,%edi
jne    126a <main+0xda>
mov    0x8(%rsi),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1283 <main+0xf3>
mov    %rax,%r15
xor    %ebx,%ebx
nop
movsbl (%r14,%rbx,1),%edi
call   1040 <isalnum@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11c0 <main+0x30>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
lea    0xe37(%rip),%rdx
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rcx
mov    %eax,%r8d
call   1050 <snprintf@plt>
xor    %edi,%edi
call   10a0 <setuid@plt>
lea    0xe42(%rip),%rdi
mov    %rdi,(%rsp)
lea    0xe40(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe37(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe35(%rip),%rax
mov    %rax,0x18(%rsp)
mov    %rbx,0x20(%rsp)
movq   $0x0,0x28(%rsp)
mov    %rsp,%rsi
call   1090 <execvp@plt>
test   %rax,%rax
je     12b3 <main+0x123>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
jmp    127a <main+0xea>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xd86(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    129d <main+0x10d>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d16(%rip),%rax
jmp    12a4 <main+0x114>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"usage: rich-core-helper report_label\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [49 x i8] c"/usr/sbin/rich-core-dumper --name=%s --signal=%d\00"
@.str.2 = [9 x i8] c"/bin/env\00"
@.str.3 = [3 x i8] c"-i\00"
@.str.4 = [10 x i8] c"/bin/bash\00"
@.str.5 = [3 x i8] c"-c\00"
@.str.6 = [34 x i8] c"Couldn't invoke rich-core-dumper\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.7 = [32 x i8] c"Invalid crash report label: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca [128 x i8]
%11 = alloca [6 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %3
br label %94
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = call i64 @strlen(i8* %22)
store i64 %23, i64* %7
%24 = load i64, i64* %7
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %18
br label %89
27: ; preds = %18
store i64 0, i64* %8
br label %28
28: ; preds = %59, %27
%29 = load i64, i64* %8
%30 = load i64, i64* %7
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %62
32: ; preds = %28
%33 = load i8*, i8** %6
%34 = load i64, i64* %8
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @isalnum(i8 signext %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %58, label %39
39: ; preds = %32
%40 = load i8*, i8** %6
%41 = load i64, i64* %8
%42 = getelementptr inbounds i8, i8* %40, i64 %41
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, 0
%45 = xor i1 %44, true
%46 = zext i1 %45 to i32
%47 = icmp eq i32 %46, 95
br i1 %47, label %48, label %58
48: ; preds = %39
%49 = load i8*, i8** %6
%50 = load i64, i64* %8
%51 = getelementptr inbounds i8, i8* %49, i64 %50
%52 = load i8, i8* %51
%53 = icmp ne i8 %52, 0
%54 = xor i1 %53, true
%55 = zext i1 %54 to i32
%56 = icmp eq i32 %55, 45
br i1 %56, label %57, label %58
57: ; preds = %48
br label %89
58: ; preds = %48, %39, %32
br label %59
59: ; preds = %58
%60 = load i64, i64* %8
%61 = add i64 %60, 1
store i64 %61, i64* %8
br label %28
62: ; preds = %28
%63 = call i32 @time(i32* null)
%64 = call i32 @srand(i32 %63)
%65 = call i32 (...) @rand()
store i32 %65, i32* %9
%66 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%67 = load i8*, i8** %6
%68 = load i32, i32* %9
%69 = call i32 @snprintf(i8* %66, i32 128, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %67, i32 %68)
%70 = call i32 @setuid(i32 0)
%71 = getelementptr inbounds [6 x i8*], [6 x i8*]* %11, i64 0, i64 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %71
%72 = getelementptr inbounds i8*, i8** %71, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %72
%73 = getelementptr inbounds i8*, i8** %72, i64 1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8** %73
%74 = getelementptr inbounds i8*, i8** %73, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %74
%75 = getelementptr inbounds i8*, i8** %74, i64 1
%76 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
store i8* %76, i8** %75
%77 = getelementptr inbounds i8*, i8** %75, i64 1
store i8* null, i8** %77
%78 = getelementptr inbounds [6 x i8*], [6 x i8*]* %11, i64 0, i64 0
%79 = load i8*, i8** %78
%80 = getelementptr inbounds [6 x i8*], [6 x i8*]* %11, i64 0, i64 0
%81 = call i64 @execvp(i8* %79, i8** %80)
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %62
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
%86 = load i32, i32* @EXIT_FAILURE
store i32 %86, i32* %3
br label %94
87: ; preds = %62
%88 = load i32, i32* @EXIT_SUCCESS
store i32 %88, i32* %3
br label %94
89: ; preds = %57, %26
%90 = load i32, i32* @stderr
%91 = load i8*, i8** %6
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %91)
%93 = load i32, i32* @EXIT_FAILURE
store i32 %93, i32* %3
br label %94
94: ; preds = %89, %87, %83, %14
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"usage: rich-core-helper report_label\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [49 x i8] c"/usr/sbin/rich-core-dumper --name=%s --signal=%d\00"
@.str.2 = [9 x i8] c"/bin/env\00"
@.str.3 = [3 x i8] c"-i\00"
@.str.4 = [10 x i8] c"/bin/bash\00"
@.str.5 = [3 x i8] c"-c\00"
@.str.6 = [34 x i8] c"Couldn't invoke rich-core-dumper\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.7 = [32 x i8] c"Invalid crash report label: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca [6 x i8*]
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %42
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %39, label %14
14: ; preds = %9, %14
%15 = phi i64 [ %19, %14 ], [ 0, %9 ]
%16 = getelementptr inbounds i8, i8* %11, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @isalnum(i8 signext %17)
%19 = add nuw i64 %15, 1
%20 = icmp eq i64 %19, %12
br i1 %20, label %21, label %14
21: ; preds = %14
%22 = tail call i32 @time(i32* null)
%23 = tail call i32 @srand(i32 %22)
%24 = tail call i32 (...) @rand()
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%26 = call i32 @snprintf(i8* %25, i32 128, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %24)
%27 = call i32 @setuid(i32 0)
%28 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %28
%29 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %29
%30 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8** %30
%31 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %31
%32 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 4
store i8* %25, i8** %32
%33 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 5
store i8* null, i8** %33
%34 = call i64 @execvp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %28)
%35 = icmp eq i64 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %21
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %42
39: ; preds = %9
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %11)
br label %42
42: ; preds = %36, %39, %21, %6
%43 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_FAILURE, %39 ], [ @EXIT_FAILURE, %36 ], [ @EXIT_SUCCESS, %21 ]
%44 = load i32, i32* %43
ret i32 %44
}