#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 */
struct stat {
  int st_nlink;
};

/* Variables and functions */
scalar_t__ geteuid();
scalar_t__ getuid();
int /*<<< orphan*/ perror(char *);
scalar_t__ stat(char *, struct stat *);
int is_secure() {
  if (getuid() == geteuid())
    return 1;
  struct stat buf;
  if (stat("/proc/self/exe", &buf) < 0) {
    perror("stat");
    return 0;
  }
  if (buf.st_nlink > 1)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_secure>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
cmp    %rcx,%rax
jne    1176 <is_secure+0x36>
movl   $0x1,-0x4(%rbp)
jmp    11c5 <is_secure+0x85>
lea    0xe83(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11a8 <is_secure+0x68>
lea    0xe78(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c5 <is_secure+0x85>
cmpl   $0x1,-0x8(%rbp)
jle    11be <is_secure+0x7e>
movl   $0x0,-0x4(%rbp)
jmp    11c5 <is_secure+0x85>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_secure>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <geteuid@plt>
mov    %rax,%rcx
mov    $0x1,%eax
cmp    %rcx,%rbx
je     1183 <is_secure+0x43>
lea    0xe96(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
test   %rax,%rax
js     1189 <is_secure+0x49>
xor    %eax,%eax
cmpl   $0x2,0x8(%rsp)
setl   %al
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe7f(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
jmp    1183 <is_secure+0x43>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [5 x i8] c"stat\00"
define i32 @is_secure() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = call i64 (...) @getuid()
%4 = call i64 (...) @geteuid()
%5 = icmp eq i64 %3, %4
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 1, i32* %1
br label %18
7: ; preds = %0
%8 = call i64 @stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %18
12: ; preds = %7
%13 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%14 = load i32, i32* %13
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 0, i32* %1
br label %18
17: ; preds = %12
store i32 1, i32* %1
br label %18
18: ; preds = %17, %16, %10, %6
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [15 x i8] c"/proc/self/exe\00"
@.str.1 = [5 x i8] c"stat\00"
define i32 @is_secure() {
%1 = alloca %struct.stat
%2 = tail call i64 (...) @getuid()
%3 = tail call i64 (...) @geteuid()
%4 = icmp eq i64 %2, %3
br i1 %4, label %18, label %5
5: ; preds = %0
%6 = bitcast %struct.stat* %1 to i8*
%7 = call i64 @stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %16
11: ; preds = %5
%12 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%13 = load i32, i32* %12
%14 = icmp slt i32 %13, 2
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %11, %9
%17 = phi i32 [ 0, %9 ], [ %15, %11 ]
br label %18
18: ; preds = %0, %16
%19 = phi i32 [ %17, %16 ], [ 1, %0 ]
ret i32 %19
}