#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 scalar_t__ uid_t;

/* Variables and functions */
char **calloc(int, int);
int execv(char *, char **);
scalar_t__ geteuid();
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  char **new_argv;
  new_argv = calloc(argc + 1, sizeof(char *));
  int i;
  for (i = 1; i < argc; ++i) {
    new_argv[i] = argv[i];
  }
  uid_t calling_uid = getuid();
  if (geteuid() == calling_uid) {
    printf("Not running suid. Executing ck-launch-session.\n");
    new_argv[0] = "/usr/bin/ck-launch-session";
  } else {
    new_argv[0] = "/usr/bin/nx-session-launcher";
  }
  return execv(new_argv[0], new_argv);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b3 <main+0x63>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1181 <main+0x31>
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
cmp    -0x28(%rbp),%rax
jne    11ee <main+0x9e>
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
lea    0xe4a(%rip),%rcx
mov    %rcx,(%rax)
jmp    11fc <main+0xac>
mov    -0x18(%rbp),%rax
lea    0xe52(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <execv@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %edi,%ebx
lea    0x1(%rbx),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
cmp    $0x2,%ebx
jl     1199 <main+0x39>
lea    0x8(%r14),%rdi
add    $0x8,%r15
add    $0xffffffff,%ebx
shl    $0x3,%rbx
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <memcpy@plt>
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <geteuid@plt>
cmp    %rbx,%rax
jne    11c4 <main+0x64>
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3e(%rip),%rdi
jmp    11cb <main+0x6b>
lea    0xe50(%rip),%rdi
mov    %rdi,(%r14)
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <execv@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"Not running suid. Executing ck-launch-session.\0A\00"
@.str.1 = [27 x i8] c"/usr/bin/ck-launch-session\00"
@.str.2 = [29 x i8] c"/usr/bin/nx-session-launcher\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
%11 = call i8** @calloc(i32 %10, i32 8)
store i8** %11, i8*** %6
store i32 1, i32* %7
br label %12
12: ; preds = %26, %2
%13 = load i32, i32* %7
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %29
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %6
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
store i8* %21, i8** %25
br label %26
26: ; preds = %16
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %12
29: ; preds = %12
%30 = call i64 (...) @getuid()
store i64 %30, i64* %8
%31 = call i64 (...) @geteuid()
%32 = load i64, i64* %8
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%36 = load i8**, i8*** %6
%37 = getelementptr inbounds i8*, i8** %36, i64 0
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8** %37
br label %41
38: ; preds = %29
%39 = load i8**, i8*** %6
%40 = getelementptr inbounds i8*, i8** %39, i64 0
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8** %40
br label %41
41: ; preds = %38, %34
%42 = load i8**, i8*** %6
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %6
%46 = call i32 @execv(i8* %44, i8** %45)
ret i32 %46
}

LLVM IR (-O2):
@.str.1 = [27 x i8] c"/usr/bin/ck-launch-session\00"
@.str.2 = [29 x i8] c"/usr/bin/nx-session-launcher\00"
@str = [47 x i8] c"Not running suid. Executing ck-launch-session.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add nsw i32 %0, 1
%4 = tail call i8** @calloc(i32 %3, i32 8)
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = getelementptr i8*, i8** %4, i64 1
%8 = bitcast i8** %7 to i8*
%9 = getelementptr i8*, i8** %1, i64 1
%10 = bitcast i8** %9 to i8*
%11 = add nsw i32 %0, -1
%12 = zext i32 %11 to i64
%13 = shl nuw nsw i64 %12, 3
br label %14
14: ; preds = %6, %2
%15 = tail call i64 (...) @getuid()
%16 = tail call i64 (...) @geteuid()
%17 = icmp eq i64 %16, %15
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %14, %18
%21 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), %18 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), %14 ]
store i8* %21, i8** %4
%22 = tail call i32 @execv(i8* %21, i8** %4)
ret i32 %22
}