#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  char buf[65536];
  int i;
  i = strlen(argv[0]);
  memset(argv[0], 0, i);
  if (sizeof("[kthread]") <= i)
    strcpy(argv[0], "[kthread]");
  memset(buf, 0, 65536);
  for (i = 1; i < argc; i++) {
    strcat(buf, argv[i]);
    strcat(buf, " ");
    memset(argv[i], 0, strlen(argv[i]));
    argv[i] = NULL;
  }
  argc = 1;
  setuid(0);
  system(buf);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10014(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10014(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
movslq -0x10014(%rbp),%rcx
mov    $0xa,%eax
cmp    %rcx,%rax
ja     11c7 <main+0x67>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe3e(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x10010(%rbp),%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1060 <memset@plt>
movl   $0x1,-0x10014(%rbp)
mov    -0x10014(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1282 <main+0x122>
lea    -0x10010(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x10014(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1070 <strcat@plt>
lea    -0x10010(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
movslq -0x10014(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x10020(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x10014(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x10020(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
movslq -0x10014(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10014(%rbp)
jmp    11e4 <main+0x84>
movl   $0x1,-0x8(%rbp)
xor    %edi,%edi
call   1080 <setuid@plt>
lea    -0x10010(%rbp),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x10020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10008,%rsp
mov    %rsi,%r13
mov    %edi,%r14d
mov    (%rsi),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    0x0(%r13),%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <memset@plt>
cmp    $0xa,%ebp
jb     11a3 <main+0x43>
mov    0x0(%r13),%rdi
lea    0xe62(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10000,%edx
call   1060 <memset@plt>
cmp    $0x2,%r14d
jl     1213 <main+0xb3>
mov    %r14d,%r12d
mov    $0x1,%ebx
mov    %rsp,%r15
lea    0xe40(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,8),%rsi
mov    %r15,%rdi
call   1070 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    0x0(%r13,%rbx,8),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <memset@plt>
movq   $0x0,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11d0 <main+0x70>
xor    %edi,%edi
call   1080 <setuid@plt>
mov    %rsp,%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x10008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"[kthread]\00"
@.str.1 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [65536 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %7
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = load i32, i32* %7
%16 = call i32 @memset(i8* %14, i32 0, i32 %15)
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = icmp ule i64 10, %18
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %20, %2
%26 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 0, i32 65536)
store i32 1, i32* %7
br label %28
28: ; preds = %58, %25
%29 = load i32, i32* %7
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %61
32: ; preds = %28
%33 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%34 = load i8**, i8*** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @strcat(i8* %33, i8* %38)
%40 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%41 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%42 = load i8**, i8*** %5
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %5
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 @strlen(i8* %51)
%53 = call i32 @memset(i8* %46, i32 0, i32 %52)
%54 = load i8**, i8*** %5
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
store i8* null, i8** %57
br label %58
58: ; preds = %32
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %28
61: ; preds = %28
store i32 1, i32* %4
%62 = call i32 @setuid(i32 0)
%63 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%64 = call i32 @system(i8* %63)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"[kthread]\00"
@.str.1 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [65536 x i8]
%4 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = tail call i32 @strlen(i8* %5)
%7 = load i8*, i8** %1
%8 = tail call i32 @memset(i8* %7, i32 0, i32 %6)
%9 = icmp ugt i32 %6, 9
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %2
%14 = call i32 @memset(i8* %4, i32 0, i32 65536)
%15 = icmp sgt i32 %0, 1
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = zext i32 %0 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 1, %16 ], [ %27, %18 ]
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 @strcat(i8* %4, i8* %21)
%23 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = load i8*, i8** %20
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @memset(i8* %24, i32 0, i32 %25)
store i8* null, i8** %20
%27 = add nuw nsw i64 %19, 1
%28 = icmp eq i64 %27, %17
br i1 %28, label %29, label %18
29: ; preds = %18, %13
%30 = call i32 @setuid(i32 0)
%31 = call i32 @system(i8* %4)
ret i32 0
}