#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
scalar_t__ getuid();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcasecmp(char *, char *);
void ensure_user_is_root() {
  bool user_is_root = (getuid() == 0);
  char *env_password = getenv("UNLOCK_DANGEROUS_THINGS");
  bool user_has_unlocked_with_password =
      env_password != NULL &&
      !strcasecmp(getenv("UNLOCK_DANGEROUS_THINGS"),
                  "I am the master of my fate: I am the captain of my soul.");
  if (!user_is_root && !user_has_unlocked_with_password) {
    fprintf(stderr, "sorry, only root can do that.\n");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<ensure_user_is_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <getuid@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
lea    0xe8b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x15(%rbp)
je     11b4 <ensure_user_is_root+0x64>
lea    0xe6b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
lea    0xe74(%rip),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11f6 <ensure_user_is_root+0xa6>
cmpl   $0x0,-0x14(%rbp)
jne    11f6 <ensure_user_is_root+0xa6>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ensure_user_is_root>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %rax,%rbx
lea    0xe9a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1185 <ensure_user_is_root+0x35>
lea    0xea1(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcasecmp@plt>
test   %eax,%eax
sete   %bpl
test   %rbx,%rbx
je     118f <ensure_user_is_root+0x3f>
test   %bpl,%bpl
je     1196 <ensure_user_is_root+0x46>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"UNLOCK_DANGEROUS_THINGS\00"
@.str.1 = [57 x i8] c"I am the master of my fate: I am the captain of my soul.\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"sorry, only root can do that.\0A\00"
@EXIT_FAILURE = global i32 0
define void @ensure_user_is_root() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = call i64 (...) @getuid()
%5 = icmp eq i64 %4, 0
%6 = zext i1 %5 to i32
store i32 %6, i32* %1
%7 = call i8* @getenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = call i8* @getenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @strcasecmp(i8* %11, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br label %15
15: ; preds = %10, %0
%16 = phi i1 [ false, %0 ], [ %14, %10 ]
%17 = zext i1 %16 to i32
store i32 %17, i32* %3
%18 = load i32, i32* %1
%19 = icmp ne i32 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %15
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %20, %15
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"UNLOCK_DANGEROUS_THINGS\00"
@.str.1 = [57 x i8] c"I am the master of my fate: I am the captain of my soul.\00"
@stderr = global i32 0
@.str.2 = [31 x i8] c"sorry, only root can do that.\0A\00"
@EXIT_FAILURE = global i32 0
define void @ensure_user_is_root() {
%1 = tail call i64 (...) @getuid()
%2 = icmp eq i64 %1, 0
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = tail call i32 @strcasecmp(i8* %3, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br label %8
8: ; preds = %5, %0
%9 = phi i1 [ false, %0 ], [ %7, %5 ]
%10 = select i1 %2, i1 true, i1 %9
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %8
ret void
}