#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 getegid();
int getgid();
int /*<<< orphan*/ perror(char *);
int setregid(int, int);
int /*<<< orphan*/ stderr;
int SwitchToEgid() {
  int gid = getgid();
  int egid = getegid();
  if (gid != egid) {
    if ((setregid(egid, egid)) == -1) {
      fprintf(stderr, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/Ansahmadiba/bazel/"
                      "refs/heads/master/src/main/tools/process-tools.c"
                      ":"
                      "45"
                      ": ");
      perror("setregid(egid, egid)");
      exit(EXIT_FAILURE);
    };
  }
  return egid;
}


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

x86 assembly (clang, -O2):
<SwitchToEgid>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <getgid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getegid@plt>
mov    %eax,%ebx
cmp    %eax,%ebp
je     1187 <SwitchToEgid+0x27>
mov    %ebx,%edi
mov    %ebx,%esi
call   1060 <setregid@plt>
cmp    $0xffffffff,%eax
je     1190 <SwitchToEgid+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1030 <fprintf@plt>
lea    0xef6(%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 = [162 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ansahmadiba/bazel/refs/heads/master/src/main/tools/process-tools.c:45: \00"
@.str.1 = [21 x i8] c"setregid(egid, egid)\00"
@EXIT_FAILURE = global i32 0
define i32 @SwitchToEgid() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @getgid()
store i32 %3, i32* %1
%4 = call i32 (...) @getegid()
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 @setregid(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 ([162 x i8], [162 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 = [162 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ansahmadiba/bazel/refs/heads/master/src/main/tools/process-tools.c:45: \00"
@.str.1 = [21 x i8] c"setregid(egid, egid)\00"
@EXIT_FAILURE = global i32 0
define i32 @SwitchToEgid() {
%1 = tail call i32 (...) @getgid()
%2 = tail call i32 (...) @getegid()
%3 = icmp eq i32 %1, %2
br i1 %3, label %13, label %4
4: ; preds = %0
%5 = tail call i32 @setregid(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 ([162 x i8], [162 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
}