#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 */
unsigned long find_elf_note(int);
scalar_t__ getegid();
scalar_t__ geteuid();
scalar_t__ getgid();
scalar_t__ getuid();
int check_for_privs(void) {
  unsigned long rc = find_elf_note(23);
  if (rc == 42) {
    rc = geteuid() != getuid() || getegid() != getgid();
  }
  return !!rc;
}


x86 assembly (clang, -O0):
<check_for_privs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x17,%edi
call   1030 <find_elf_note@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x2a,-0x8(%rbp)
jne    11c8 <check_for_privs+0x78>
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,%rdx
mov    $0x1,%al
cmp    %rdx,%rcx
mov    %al,-0x9(%rbp)
jne    11ba <check_for_privs+0x6a>
mov    $0x0,%al
call   1070 <getegid@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <getgid@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_for_privs>:
push   %rbx
mov    $0x17,%edi
call   1030 <find_elf_note@plt>
cmp    $0x2a,%rax
jne    119b <check_for_privs+0x4b>
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %rax,%rcx
mov    $0x1,%eax
cmp    %rcx,%rbx
jne    119b <check_for_privs+0x4b>
xor    %eax,%eax
call   1070 <getegid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <getgid@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rbx
setne  %al
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @check_for_privs() {
%1 = alloca i64
%2 = call i64 @find_elf_note(i32 23)
store i64 %2, i64* %1
%3 = load i64, i64* %1
%4 = icmp eq i64 %3, 42
br i1 %4, label %5, label %17
5: ; preds = %0
%6 = call i64 (...) @geteuid()
%7 = call i64 (...) @getuid()
%8 = icmp ne i64 %6, %7
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = call i64 (...) @getegid()
%11 = call i64 (...) @getgid()
%12 = icmp ne i64 %10, %11
br label %13
13: ; preds = %9, %5
%14 = phi i1 [ true, %5 ], [ %12, %9 ]
%15 = zext i1 %14 to i32
%16 = sext i32 %15 to i64
store i64 %16, i64* %1
br label %17
17: ; preds = %13, %0
%18 = load i64, i64* %1
%19 = icmp ne i64 %18, 0
%20 = xor i1 %19, true
%21 = xor i1 %20, true
%22 = zext i1 %21 to i32
ret i32 %22
}

LLVM IR (-O2):
define i32 @check_for_privs() {
%1 = tail call i64 @find_elf_note(i32 23)
%2 = icmp eq i64 %1, 42
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = tail call i64 (...) @geteuid()
%5 = tail call i64 (...) @getuid()
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = tail call i64 (...) @getegid()
%9 = tail call i64 (...) @getgid()
%10 = icmp ne i64 %8, %9
%11 = zext i1 %10 to i64
br label %12
12: ; preds = %3, %7, %0
%13 = phi i64 [ %1, %0 ], [ 1, %3 ], [ %11, %7 ]
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i32
ret i32 %15
}