#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*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ memcpy(char **, char **, int);
int /*<<< orphan*/ printf(char *, ...);
void auto_su(int argc, char *argv[]) {
  char *args[argc + 4];
  if (!getuid())
    return;
  args[0] = "su";
  args[1] = "-p";
  args[2] = "-c";
  memcpy(&args[3], argv, argc * sizeof(*args));
  args[argc + 3] = NULL;
  printf("[$] su -p -c ");
  for (int i = 0; i < argc; ++i)
    printf("%s%c", argv[i], i == argc - 1 ? '\n' : ' ');
  execvp("su", args);
  exit(errno);
}


x86 assembly (clang, -O0):
<auto_su>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
cmp    $0x0,%eax
jne    11a5 <auto_su+0x55>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret
mov    -0x30(%rbp),%rdi
lea    0xe50(%rip),%rax
mov    %rax,(%rdi)
lea    0xe49(%rip),%rax
mov    %rax,0x8(%rdi)
lea    0xe41(%rip),%rax
mov    %rax,0x10(%rdi)
add    $0x18,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x4(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1256 <auto_su+0x106>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x24(%rbp),%ecx
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    $0x20,%edx
mov    $0xa,%eax
cmp    %edi,%ecx
cmove  %eax,%edx
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    120a <auto_su+0xba>
mov    -0x30(%rbp),%rsi
lea    0xd9f(%rip),%rdi
call   1060 <execvp@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<auto_su>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x4(%r15),%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xor    %eax,%eax
call   1030 <getuid@plt>
test   %eax,%eax
jne    1197 <auto_su+0x47>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe62(%rip),%rax
mov    %rax,(%rbx)
lea    0xe5b(%rip),%rax
mov    %rax,0x8(%rbx)
lea    0xe53(%rip),%rax
mov    %rax,0x10(%rbx)
lea    0x18(%rbx),%rdi
lea    0x0(,%r15,8),%edx
mov    %r14,%rsi
call   1050 <memcpy@plt>
movslq %r15d,%rax
movq   $0x0,0x18(%rbx,%rax,8)
lea    0xe2b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15d,%r15d
jle    122b <auto_su+0xdb>
lea    -0x1(%r15),%r12d
mov    %r15d,%r13d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%r15,8),%rsi
cmp    %r15,%r12
mov    $0x20,%edx
mov    $0xa,%eax
cmove  %eax,%edx
lea    0xdfc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r15,%r13
jne    1200 <auto_su+0xb0>
lea    0xdce(%rip),%rdi
mov    %rbx,%rsi
call   1060 <execvp@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"su\00"
@.str.1 = [3 x i8] c"-p\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [14 x i8] c"[$] su -p -c \00"
@.str.4 = [5 x i8] c"%s%c\00"
@errno = global i32 0
define void @auto_su(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = add nsw i32 %8, 4
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8*, i64 %10
store i64 %10, i64* %6
%13 = call i32 (...) @getuid()
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = load i8*, i8** %5
ret void
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %12, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds i8*, i8** %12, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %19
%20 = getelementptr inbounds i8*, i8** %12, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds i8*, i8** %12, i64 3
%22 = load i8**, i8*** %4
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = trunc i64 %25 to i32
%27 = call i32 @memcpy(i8** %21, i8** %22, i32 %26)
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %12, i64 %30
store i8* null, i8** %31
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %7
br label %33
33: ; preds = %50, %17
%34 = load i32, i32* %7
%35 = load i32, i32* %3
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %53
37: ; preds = %33
%38 = load i8**, i8*** %4
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = load i32, i32* %7
%44 = load i32, i32* %3
%45 = sub nsw i32 %44, 1
%46 = icmp eq i32 %43, %45
%47 = zext i1 %46 to i64
%48 = select i1 %46, i32 10, i32 32
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %42, i32 %48)
br label %50
50: ; preds = %37
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %33
53: ; preds = %33
%54 = call i32 @execvp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %12)
%55 = load i32, i32* @errno
%56 = call i32 @exit(i32 %55)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"su\00"
@.str.1 = [3 x i8] c"-p\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [14 x i8] c"[$] su -p -c \00"
@.str.4 = [5 x i8] c"%s%c\00"
@errno = global i32 0
define void @auto_su(i32 %0, i8** %1) {
%3 = add nsw i32 %0, 4
%4 = zext i32 %3 to i64
%5 = alloca i8*, i64 %4
%6 = tail call i32 (...) @getuid()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
ret void
9: ; preds = %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5
%10 = getelementptr inbounds i8*, i8** %5, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds i8*, i8** %5, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds i8*, i8** %5, i64 3
%13 = shl i32 %0, 3
%14 = call i32 @memcpy(i8** %12, i8** %1, i32 %13)
%15 = add nsw i32 %0, 3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %5, i64 %16
store i8* null, i8** %17
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp sgt i32 %0, 0
br i1 %19, label %20, label %24
20: ; preds = %9
%21 = add nsw i32 %0, -1
%22 = zext i32 %21 to i64
%23 = zext i32 %0 to i64
br label %28
24: ; preds = %28, %9
%25 = call i32 @execvp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5)
%26 = load i32, i32* @errno
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %20, %28
%29 = phi i64 [ 0, %20 ], [ %35, %28 ]
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = icmp eq i64 %29, %22
%33 = select i1 %32, i32 10, i32 32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %31, i32 %33)
%35 = add nuw nsw i64 %29, 1
%36 = icmp eq i64 %35, %23
br i1 %36, label %24, label %28
}