#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 EPERM;
scalar_t__ geteuid();
int /*<<< orphan*/ printf(char *);
int main() {
  printf("Start of GPIO test program.\n");
  if (geteuid() != 0) {
    printf("You must run this program as root. Exiting.\n");
    return -EPERM;
  }
  printf("Doing something here with root privileges!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <geteuid@plt>
cmp    $0x0,%rax
je     116b <main+0x4b>
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    0x2e77(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    117e <main+0x5e>
lea    0xed8(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <geteuid@plt>
test   %rax,%rax
je     1152 <main+0x32>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e8a(%rip),%rax
sub    (%rax),%ebx
jmp    115e <main+0x3e>
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Start of GPIO test program.\0A\00"
@.str.1 = [45 x i8] c"You must run this program as root. Exiting.\0A\00"
@EPERM = global i32 0
@.str.2 = [44 x i8] c"Doing something here with root privileges!\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%3 = call i64 (...) @geteuid()
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @EPERM
%8 = sub nsw i32 0, %7
store i32 %8, i32* %1
br label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %11
11: ; preds = %9, %5
%12 = load i32, i32* %1
ret i32 %12
}

LLVM IR (-O2):
@EPERM = global i32 0
@str = [28 x i8] c"Start of GPIO test program.\00"
@str.3 = [43 x i8] c"Doing something here with root privileges!\00"
@str.4 = [44 x i8] c"You must run this program as root. Exiting.\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 (...) @geteuid()
%3 = icmp eq i64 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.4, i64 0, i64 0))
%6 = load i32, i32* @EPERM
%7 = sub nsw i32 0, %6
br label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.3, i64 0, i64 0))
br label %10
10: ; preds = %8, %4
%11 = phi i32 [ %7, %4 ], [ 0, %8 ]
ret i32 %11
}