#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*/ gid_t;

/* Variables and functions */
int /*<<< orphan*/ getegid();
int /*<<< orphan*/ geteuid();
int /*<<< orphan*/ getgid();
int /*<<< orphan*/ getresgid(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ getresuid(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ setegid(int);
int /*<<< orphan*/ seteuid(int);
int /*<<< orphan*/ setfsgid(int);
int /*<<< orphan*/ setfsuid(int);
int /*<<< orphan*/ setgid(int);
int /*<<< orphan*/ setregid(int, int);
int /*<<< orphan*/ setreuid(int, int);
int /*<<< orphan*/ setuid(int);
int main() {
  uid_t ruid, euid, suid;
  gid_t rgid, egid, sgid;
  ruid = getuid();
  euid = geteuid();
  rgid = getgid();
  egid = getegid();
  setuid(4096);
  seteuid(4097);
  getresuid(&ruid, &euid, &suid);
  setgid(4098);
  setegid(4099);
  getresgid(&rgid, &egid, &sgid);
  setreuid(-1, 5000);
  setreuid(5001, -1);
  setregid(-1, 5002);
  setregid(5003, -1);
  setfsuid(5004);
  setfsgid(5005);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1060 <geteuid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1080 <getgid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1090 <getegid@plt>
mov    %eax,-0x18(%rbp)
mov    $0x1000,%edi
call   10e0 <setuid@plt>
mov    $0x1001,%edi
call   1100 <seteuid@plt>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1070 <getresuid@plt>
mov    $0x1002,%edi
call   10c0 <setgid@plt>
mov    $0x1003,%edi
call   10f0 <setegid@plt>
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <getresgid@plt>
mov    $0xffffffff,%edi
mov    $0x1388,%esi
call   10a0 <setreuid@plt>
mov    $0x1389,%edi
mov    $0xffffffff,%esi
call   10a0 <setreuid@plt>
mov    $0xffffffff,%edi
mov    $0x138a,%esi
call   10b0 <setregid@plt>
mov    $0x138b,%edi
mov    $0xffffffff,%esi
call   10b0 <setregid@plt>
mov    $0x138c,%edi
call   1050 <setfsuid@plt>
mov    $0x138d,%edi
call   10d0 <setfsgid@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,0xc(%rsp)
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,0x8(%rsp)
xor    %eax,%eax
call   1080 <getgid@plt>
mov    %eax,0x4(%rsp)
xor    %eax,%eax
call   1090 <getegid@plt>
mov    %eax,(%rsp)
mov    $0x1000,%edi
call   10e0 <setuid@plt>
mov    $0x1001,%edi
call   1100 <seteuid@plt>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rdx
call   1070 <getresuid@plt>
mov    $0x1002,%edi
call   10c0 <setgid@plt>
mov    $0x1003,%edi
call   10f0 <setegid@plt>
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
lea    0x10(%rsp),%rdx
call   1030 <getresgid@plt>
mov    $0xffffffff,%edi
mov    $0x1388,%esi
call   10a0 <setreuid@plt>
mov    $0x1389,%edi
mov    $0xffffffff,%esi
call   10a0 <setreuid@plt>
mov    $0xffffffff,%edi
mov    $0x138a,%esi
call   10b0 <setregid@plt>
mov    $0x138b,%edi
mov    $0xffffffff,%esi
call   10b0 <setregid@plt>
mov    $0x138c,%edi
call   1050 <setfsuid@plt>
mov    $0x138d,%edi
call   10d0 <setfsgid@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (...) @getuid()
store i32 %8, i32* %2
%9 = call i32 (...) @geteuid()
store i32 %9, i32* %3
%10 = call i32 (...) @getgid()
store i32 %10, i32* %5
%11 = call i32 (...) @getegid()
store i32 %11, i32* %6
%12 = call i32 @setuid(i32 4096)
%13 = call i32 @seteuid(i32 4097)
%14 = call i32 @getresuid(i32* %2, i32* %3, i32* %4)
%15 = call i32 @setgid(i32 4098)
%16 = call i32 @setegid(i32 4099)
%17 = call i32 @getresgid(i32* %5, i32* %6, i32* %7)
%18 = call i32 @setreuid(i32 -1, i32 5000)
%19 = call i32 @setreuid(i32 5001, i32 -1)
%20 = call i32 @setregid(i32 -1, i32 5002)
%21 = call i32 @setregid(i32 5003, i32 -1)
%22 = call i32 @setfsuid(i32 5004)
%23 = call i32 @setfsgid(i32 5005)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = tail call i32 (...) @getuid()
store i32 %13, i32* %1
%14 = tail call i32 (...) @geteuid()
store i32 %14, i32* %2
%15 = tail call i32 (...) @getgid()
store i32 %15, i32* %4
%16 = tail call i32 (...) @getegid()
store i32 %16, i32* %5
%17 = tail call i32 @setuid(i32 4096)
%18 = tail call i32 @seteuid(i32 4097)
%19 = call i32 @getresuid(i32* %1, i32* %2, i32* %3)
%20 = call i32 @setgid(i32 4098)
%21 = call i32 @setegid(i32 4099)
%22 = call i32 @getresgid(i32* %4, i32* %5, i32* %6)
%23 = call i32 @setreuid(i32 -1, i32 5000)
%24 = call i32 @setreuid(i32 5001, i32 -1)
%25 = call i32 @setregid(i32 -1, i32 5002)
%26 = call i32 @setregid(i32 5003, i32 -1)
%27 = call i32 @setfsuid(i32 5004)
%28 = call i32 @setfsgid(i32 5005)
ret i32 0
}