#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*/ pid_t;
typedef int /*<<< orphan*/ pid;

/* Variables and functions */
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ dup2(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ write(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  setuid(0);
  pid_t pid[1];
  pid[0] = getpid();
  dup2(STDOUT_FILENO, STDERR_FILENO);
  write(STDOUT_FILENO, pid, sizeof(pid));
  for (int i = 1; i < argc; i++) {
    argv[i - 1] = argv[i];
  }
  argv[argc - 1] = NULL;
  execv(argv[0], argv);
  exit(-1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   1070 <setuid@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1050 <dup2@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f3 <main+0x93>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bc <main+0x5c>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <execv@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %edi,%edi
call   1080 <setuid@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,0xc(%rsp)
mov    0x2e59(%rip),%r15
mov    (%r15),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1050 <dup2@plt>
mov    (%r15),%edi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x1,%ebx
jle    11d8 <main+0x68>
lea    0x8(%r14),%rsi
add    $0xffffffff,%ebx
lea    0x0(,%rbx,8),%rdx
mov    %r14,%rdi
call   1060 <memmove@plt>
jmp    11db <main+0x6b>
add    $0xffffffff,%ebx
movslq %ebx,%rax
movq   $0x0,(%r14,%rax,8)
mov    (%r14),%rdi
mov    %r14,%rsi
call   1090 <execv@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1 x i32]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @setuid(i32 0)
%9 = call i32 (...) @getpid()
%10 = getelementptr inbounds [1 x i32], [1 x i32]* %6, i64 0, i64 0
store i32 %9, i32* %10
%11 = load i32, i32* @STDOUT_FILENO
%12 = load i32, i32* @STDERR_FILENO
%13 = call i32 @dup2(i32 %11, i32 %12)
%14 = load i32, i32* @STDOUT_FILENO
%15 = getelementptr inbounds [1 x i32], [1 x i32]* %6, i64 0, i64 0
%16 = call i32 @write(i32 %14, i32* %15, i32 4)
store i32 1, i32* %7
br label %17
17: ; preds = %32, %2
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %5
%28 = load i32, i32* %7
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %27, i64 %30
store i8* %26, i8** %31
br label %32
32: ; preds = %21
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %17
35: ; preds = %17
%36 = load i8**, i8*** %5
%37 = load i32, i32* %4
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %36, i64 %39
store i8* null, i8** %40
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %5
%45 = call i32 @execv(i8* %43, i8** %44)
%46 = call i32 @exit(i32 -1)
unreachable
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1 x i32]
%4 = tail call i32 @setuid(i32 0)
%5 = bitcast [1 x i32]* %3 to i8*
%6 = tail call i32 (...) @getpid()
%7 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
store i32 %6, i32* %7
%8 = load i32, i32* @STDOUT_FILENO
%9 = load i32, i32* @STDERR_FILENO
%10 = tail call i32 @dup2(i32 %8, i32 %9)
%11 = load i32, i32* @STDOUT_FILENO
%12 = call i32 @write(i32 %11, i32* %7, i32 4)
%13 = icmp sgt i32 %0, 1
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = add nsw i32 %0, -1
br label %23
16: ; preds = %2
%17 = bitcast i8** %1 to i8*
%18 = getelementptr i8*, i8** %1, i64 1
%19 = bitcast i8** %18 to i8*
%20 = add nsw i32 %0, -1
%21 = zext i32 %20 to i64
%22 = shl nuw nsw i64 %21, 3
br label %23
23: ; preds = %14, %16
%24 = phi i32 [ %15, %14 ], [ %20, %16 ]
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
store i8* null, i8** %26
%27 = load i8*, i8** %1
%28 = tail call i32 @execv(i8* %27, i8** %1)
%29 = tail call i32 @exit(i32 -1)
unreachable
}