#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*/ EPERM;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int system(char *);
int main(void) {
  int ret;
  if (setuid(0)) {
    fprintf(stderr, "Error: Failed setuid()\n");
    exit(EPERM);
  }
  ret = system("python2 weinbot.py");
  if (ret != 0) {
    system("bash resetgpio.sh");
  }
  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>
cmp    $0x0,%rax
je     1183 <main+0x43>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
lea    0xe8e(%rip),%rdi
call   1030 <system@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11a8 <main+0x68>
lea    0xe88(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %edi,%edi
call   1060 <setuid@plt>
test   %rax,%rax
jne    116d <main+0x2d>
lea    0xec4(%rip),%rdi
call   1030 <system@plt>
test   %eax,%eax
je     1169 <main+0x29>
lea    0xec7(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Error: Failed setuid()\0A\00"
@EPERM = global i32 0
@.str.1 = [19 x i8] c"python2 weinbot.py\00"
@.str.2 = [18 x i8] c"bash resetgpio.sh\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i64 @setuid(i32 0)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EPERM
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Error: Failed setuid()\0A\00"
@EPERM = global i32 0
@.str.1 = [19 x i8] c"python2 weinbot.py\00"
@.str.2 = [18 x i8] c"bash resetgpio.sh\00"
define i32 @main() {
%1 = tail call i64 @setuid(i32 0)
%2 = icmp eq i64 %1, 0
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EPERM
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %0
%9 = tail call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
ret i32 0
}