#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 *);
int geteuid();
int getuid();
int /*<<< orphan*/ perror(char *);
int setreuid(int, int);
int /*<<< orphan*/ stderr;
int SwitchToEuid() {
  int uid = getuid();
  int euid = geteuid();
  if (uid != euid) {
    if ((setreuid(euid, euid)) == -1) {
      fprintf(stderr, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/Asana/bazel/refs/"
                      "heads/master/src/main/tools/process-tools.c"
                      ":"
                      "36"
                      ": ");
      perror("setreuid(euid, euid)");
      exit(EXIT_FAILURE);
    };
  }
  return euid;
}


x86 assembly (clang, -O0):
<SwitchToEuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     11d0 <SwitchToEuid+0x70>
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <setreuid@plt>
cmp    $0xffffffff,%eax
jne    11cb <SwitchToEuid+0x6b>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xee4(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11d0 <SwitchToEuid+0x70>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SwitchToEuid>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <geteuid@plt>
mov    %eax,%ebx
cmp    %eax,%ebp
je     1187 <SwitchToEuid+0x27>
mov    %ebx,%edi
mov    %ebx,%esi
call   1060 <setreuid@plt>
cmp    $0xffffffff,%eax
je     1190 <SwitchToEuid+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xef0(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Asana/bazel/refs/heads/master/src/main/tools/process-tools.c:36: \00"
@.str.1 = [21 x i8] c"setreuid(euid, euid)\00"
@EXIT_FAILURE = global i32 0
define i32 @SwitchToEuid() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @getuid()
store i32 %3, i32* %1
%4 = call i32 (...) @geteuid()
store i32 %4, i32* %2
%5 = load i32, i32* %1
%6 = load i32, i32* %2
%7 = icmp ne i32 %5, %6
br i1 %7, label %8, label %20
8: ; preds = %0
%9 = load i32, i32* %2
%10 = load i32, i32* %2
%11 = call i32 @setreuid(i32 %9, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %8
br label %20
20: ; preds = %19, %0
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Asana/bazel/refs/heads/master/src/main/tools/process-tools.c:36: \00"
@.str.1 = [21 x i8] c"setreuid(euid, euid)\00"
@EXIT_FAILURE = global i32 0
define i32 @SwitchToEuid() {
%1 = tail call i32 (...) @getuid()
%2 = tail call i32 (...) @geteuid()
%3 = icmp eq i32 %1, %2
br i1 %3, label %13, label %4
4: ; preds = %0
%5 = tail call i32 @setreuid(i32 %2, i32 %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %4, %0
ret i32 %2
}