#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 scalar_t__ uid_t;
typedef scalar_t__ gid_t;

/* Variables and functions */
scalar_t__ getegid();
scalar_t__ geteuid();
scalar_t__ getgid();
scalar_t__ getuid();
int /*<<< orphan*/ setegid(scalar_t__);
int /*<<< orphan*/ seteuid(scalar_t__);
int mtnd_guid_restore() {
  uid_t uid = getuid();
  gid_t gid = getgid();
  if (uid != geteuid()) {
    seteuid(uid);
  }
  if (gid != getegid()) {
    setegid(gid);
  }
  return (0);
}


x86 assembly (clang, -O0):
<mtnd_guid_restore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getgid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
je     11a6 <mtnd_guid_restore+0x46>
mov    -0x8(%rbp),%rdi
call   1080 <seteuid@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <getegid@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     11ce <mtnd_guid_restore+0x6e>
mov    -0x10(%rbp),%rdi
call   1070 <setegid@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mtnd_guid_restore>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getgid@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1040 <geteuid@plt>
cmp    %rax,%rbx
je     118c <mtnd_guid_restore+0x2c>
mov    %rbx,%rdi
call   1080 <seteuid@plt>
xor    %eax,%eax
call   1060 <getegid@plt>
cmp    %rax,%r14
je     11a0 <mtnd_guid_restore+0x40>
mov    %r14,%rdi
call   1070 <setegid@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @mtnd_guid_restore() {
%1 = tail call i64 (...) @getuid()
%2 = tail call i64 (...) @getgid()
%3 = tail call i64 (...) @geteuid()
%4 = icmp eq i64 %1, %3
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @seteuid(i64 %1)
br label %7
7: ; preds = %5, %0
%8 = tail call i64 (...) @getegid()
%9 = icmp eq i64 %2, %8
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @setegid(i64 %2)
br label %12
12: ; preds = %10, %7
ret i32 0
}