#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 getuid();
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  char cmd[50], uid[6];
  if (argc == 2 && strcmp(argv[1], "clean") == 0)
    strcpy(cmd, "/usr/local/bin/mpi-dclean");
  else
    strcpy(cmd, "/usr/local/bin/mpi-drun.sh");
  sprintf(uid, " %d", getuid());
  strcat(cmd, uid);
  setuid(0);
  system(cmd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11c3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe75(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11c3 <main+0x53>
lea    -0x50(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d3 <main+0x63>
lea    -0x50(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x56(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%edx
lea    0xe46(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x50(%rbp),%rdi
lea    -0x56(%rbp),%rsi
call   1070 <strcat@plt>
xor    %edi,%edi
call   1090 <setuid@plt>
lea    -0x50(%rbp),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
cmp    $0x2,%edi
jne    1191 <main+0x21>
mov    0x8(%rsi),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     119a <main+0x2a>
lea    0xe82(%rip),%rsi
jmp    11a1 <main+0x31>
lea    0xe5f(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
call   1040 <getuid@plt>
lea    0xe79(%rip),%rsi
lea    0xa(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   1080 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <strcat@plt>
xor    %edi,%edi
call   1090 <setuid@plt>
mov    %r14,%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"clean\00"
@.str.1 = [26 x i8] c"/usr/local/bin/mpi-dclean\00"
@.str.2 = [27 x i8] c"/usr/local/bin/mpi-drun.sh\00"
@.str.3 = [4 x i8] c" %d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [50 x i8]
%7 = alloca [6 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %22
19: ; preds = %10, %2
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %19, %16
%23 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%24 = call i32 (...) @getuid()
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%27 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 0
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = call i32 @setuid(i32 0)
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%31 = call i32 @system(i8* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"clean\00"
@.str.1 = [26 x i8] c"/usr/local/bin/mpi-dclean\00"
@.str.2 = [27 x i8] c"/usr/local/bin/mpi-drun.sh\00"
@.str.3 = [4 x i8] c" %d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%4 = alloca [6 x i8]
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %8, %2
br label %14
14: ; preds = %8, %13
%15 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), %13 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), %8 ]
%16 = call i32 @strcpy(i8* %5, i8* %15)
%17 = call i32 (...) @getuid()
%18 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = call i32 @strcat(i8* %5, i8* %6)
%20 = call i32 @setuid(i32 0)
%21 = call i32 @system(i8* %5)
ret i32 0
}