#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ putenv(char *);
int setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ system(char *);
int main() {
  int rc = setuid(0);
  if (rc) {
    fprintf(stderr, "Privilege escalation failed. Is the setuid bit set (chmod "
                    "u+s bcc.elf)?\n");
    return -1;
  }
  putenv("LUA_PATH=/opt/circonus/nad/etc/node-agent.d/linux/bccbpf/lua/?.lua");
  system("/opt/circonus/nad/etc/node-agent.d/linux/bccbpf/bpf.lua");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1060 <setuid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1184 <main+0x44>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <main+0x63>
lea    0xebe(%rip),%rdi
call   1040 <putenv@plt>
lea    0xef5(%rip),%rdi
call   1030 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <setuid@plt>
test   %eax,%eax
je     116a <main+0x2a>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
lea    0xea2(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1182 <main+0x42>
lea    0xed8(%rip),%rdi
call   1040 <putenv@plt>
lea    0xf0f(%rip),%rdi
call   1030 <system@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [73 x i8] c"Privilege escalation failed. Is the setuid bit set (chmod u+s bcc.elf)?\0A\00"
@.str.1 = [67 x i8] c"LUA_PATH=/opt/circonus/nad/etc/node-agent.d/linux/bccbpf/lua/?.lua\00"
@.str.2 = [56 x i8] c"/opt/circonus/nad/etc/node-agent.d/linux/bccbpf/bpf.lua\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @setuid(i32 0)
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %12
9: ; preds = %0
%10 = call i32 @putenv(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @system(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %12
12: ; preds = %9, %6
%13 = load i32, i32* %1
ret i32 %13
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [73 x i8] c"Privilege escalation failed. Is the setuid bit set (chmod u+s bcc.elf)?\0A\00"
@.str.1 = [67 x i8] c"LUA_PATH=/opt/circonus/nad/etc/node-agent.d/linux/bccbpf/lua/?.lua\00"
@.str.2 = [56 x i8] c"/opt/circonus/nad/etc/node-agent.d/linux/bccbpf/bpf.lua\00"
define i32 @main() {
%1 = tail call i32 @setuid(i32 0)
%2 = icmp eq i32 %1, 0
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0))
br label %9
6: ; preds = %0
%7 = tail call i32 @putenv(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @system(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %6, %3
%10 = phi i32 [ -1, %3 ], [ 0, %6 ]
ret i32 %10
}