#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 */
typedef int /*<<< orphan*/ uid_t;
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ geteuid();
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ seteuid(int /*<<< orphan*/);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
int unpriv_mode(uid_t *euid, sigset_t *orig_sigset) {
  *euid = geteuid();
  seteuid(getuid());
  if (orig_sigset) {
    if (sigprocmask(SIG_SETMASK, orig_sigset, NULL)) {
      exit(-1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<unpriv_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <geteuid@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,%edi
call   1070 <seteuid@plt>
cmpq   $0x0,-0x10(%rbp)
je     11b7 <unpriv_mode+0x67>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
je     11b2 <unpriv_mode+0x62>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    11b7 <unpriv_mode+0x67>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpriv_mode>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <geteuid@plt>
mov    %eax,(%rbx)
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%edi
call   1070 <seteuid@plt>
test   %r14,%r14
je     118e <unpriv_mode+0x3e>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
test   %rax,%rax
jne    1198 <unpriv_mode+0x48>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@SIG_SETMASK = global i32 0
define i32 @unpriv_mode(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
store i32* %0, i32** %3
store i32* %1, i32** %4
%5 = call i32 (...) @geteuid()
%6 = load i32*, i32** %3
store i32 %5, i32* %6
%7 = call i32 (...) @getuid()
%8 = call i32 @seteuid(i32 %7)
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @SIG_SETMASK
%13 = load i32*, i32** %4
%14 = call i64 @sigprocmask(i32 %12, i32* %13, i32* null)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %11
br label %19
19: ; preds = %18, %2
ret i32 0
}

LLVM IR (-O2):
@SIG_SETMASK = global i32 0
define i32 @unpriv_mode(i32* nocapture writeonly %0, i32* %1) {
%3 = tail call i32 (...) @geteuid()
store i32 %3, i32* %0
%4 = tail call i32 (...) @getuid()
%5 = tail call i32 @seteuid(i32 %4)
%6 = icmp eq i32* %1, null
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = load i32, i32* @SIG_SETMASK
%9 = tail call i64 @sigprocmask(i32 %8, i32* %1, i32* null)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %7, %2
ret i32 0
}