#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);
  setuid(-1);
  seteuid(4097);
  getresuid(&ruid, &euid, &suid);
  getresuid((uid_t *)-1, &euid, &suid);
  getresuid(&ruid, (uid_t *)-1, &suid);
  getresuid(&ruid, &euid, (uid_t *)-1);
  setgid(4098);
  setgid(-1);
  setegid(4099);
  getresgid(&rgid, &egid, &sgid);
  getresgid((gid_t *)-1, &egid, &sgid);
  getresgid(&rgid, (gid_t *)-1, &sgid);
  getresgid(&rgid, &egid, (gid_t *)-1);
  setreuid(-1, 5000);
  setreuid(5001, -1);
  setregid(-1, 5002);
  setregid(5003, -1);
  setfsuid(5004);
  setfsuid(-1);
  setfsgid(5005);
  setfsgid(-1);
  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    $0xffffffff,%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    $0xffffffffffffffff,%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1070 <getresuid@plt>
lea    -0x8(%rbp),%rdi
mov    $0xffffffffffffffff,%rsi
lea    -0x10(%rbp),%rdx
call   1070 <getresuid@plt>
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
mov    $0xffffffffffffffff,%rdx
call   1070 <getresuid@plt>
mov    $0x1002,%edi
call   10c0 <setgid@plt>
mov    $0xffffffff,%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    $0xffffffffffffffff,%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <getresgid@plt>
lea    -0x14(%rbp),%rdi
mov    $0xffffffffffffffff,%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <getresgid@plt>
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xffffffffffffffff,%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    $0xffffffff,%edi
call   1050 <setfsuid@plt>
mov    $0x138d,%edi
call   10d0 <setfsgid@plt>
mov    $0xffffffff,%edi
call   10d0 <setfsgid@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,0x14(%rsp)
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,0x10(%rsp)
xor    %eax,%eax
call   1080 <getgid@plt>
mov    %eax,0xc(%rsp)
xor    %eax,%eax
call   1090 <getegid@plt>
mov    %eax,0x8(%rsp)
mov    $0x1000,%edi
call   10e0 <setuid@plt>
mov    $0xffffffff,%edi
call   10e0 <setuid@plt>
mov    $0x1001,%edi
call   1100 <seteuid@plt>
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r14
lea    0x1c(%rsp),%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <getresuid@plt>
mov    $0xffffffffffffffff,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <getresuid@plt>
mov    %r15,%rdi
mov    $0xffffffffffffffff,%rsi
mov    %rbx,%rdx
call   1070 <getresuid@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xffffffffffffffff,%rdx
call   1070 <getresuid@plt>
mov    $0x1002,%edi
call   10c0 <setgid@plt>
mov    $0xffffffff,%edi
call   10c0 <setgid@plt>
mov    $0x1003,%edi
call   10f0 <setegid@plt>
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r14
lea    0x18(%rsp),%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <getresgid@plt>
mov    $0xffffffffffffffff,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <getresgid@plt>
mov    %r15,%rdi
mov    $0xffffffffffffffff,%rsi
mov    %rbx,%rdx
call   1030 <getresgid@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xffffffffffffffff,%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    $0xffffffff,%edi
call   1050 <setfsuid@plt>
mov    $0x138d,%edi
call   10d0 <setfsgid@plt>
mov    $0xffffffff,%edi
call   10d0 <setfsgid@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 @setuid(i32 -1)
%14 = call i32 @seteuid(i32 4097)
%15 = call i32 @getresuid(i32* %2, i32* %3, i32* %4)
%16 = call i32 @getresuid(i32* inttoptr (i64 -1 to i32*), i32* %3, i32* %4)
%17 = call i32 @getresuid(i32* %2, i32* inttoptr (i64 -1 to i32*), i32* %4)
%18 = call i32 @getresuid(i32* %2, i32* %3, i32* inttoptr (i64 -1 to i32*))
%19 = call i32 @setgid(i32 4098)
%20 = call i32 @setgid(i32 -1)
%21 = call i32 @setegid(i32 4099)
%22 = call i32 @getresgid(i32* %5, i32* %6, i32* %7)
%23 = call i32 @getresgid(i32* inttoptr (i64 -1 to i32*), i32* %6, i32* %7)
%24 = call i32 @getresgid(i32* %5, i32* inttoptr (i64 -1 to i32*), i32* %7)
%25 = call i32 @getresgid(i32* %5, i32* %6, i32* inttoptr (i64 -1 to i32*))
%26 = call i32 @setreuid(i32 -1, i32 5000)
%27 = call i32 @setreuid(i32 5001, i32 -1)
%28 = call i32 @setregid(i32 -1, i32 5002)
%29 = call i32 @setregid(i32 5003, i32 -1)
%30 = call i32 @setfsuid(i32 5004)
%31 = call i32 @setfsuid(i32 -1)
%32 = call i32 @setfsgid(i32 5005)
%33 = call i32 @setfsgid(i32 -1)
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 @setuid(i32 -1)
%19 = tail call i32 @seteuid(i32 4097)
%20 = call i32 @getresuid(i32* %1, i32* %2, i32* %3)
%21 = call i32 @getresuid(i32* inttoptr (i64 -1 to i32*), i32* %2, i32* %3)
%22 = call i32 @getresuid(i32* %1, i32* inttoptr (i64 -1 to i32*), i32* %3)
%23 = call i32 @getresuid(i32* %1, i32* %2, i32* inttoptr (i64 -1 to i32*))
%24 = call i32 @setgid(i32 4098)
%25 = call i32 @setgid(i32 -1)
%26 = call i32 @setegid(i32 4099)
%27 = call i32 @getresgid(i32* %4, i32* %5, i32* %6)
%28 = call i32 @getresgid(i32* inttoptr (i64 -1 to i32*), i32* %5, i32* %6)
%29 = call i32 @getresgid(i32* %4, i32* inttoptr (i64 -1 to i32*), i32* %6)
%30 = call i32 @getresgid(i32* %4, i32* %5, i32* inttoptr (i64 -1 to i32*))
%31 = call i32 @setreuid(i32 -1, i32 5000)
%32 = call i32 @setreuid(i32 5001, i32 -1)
%33 = call i32 @setregid(i32 -1, i32 5002)
%34 = call i32 @setregid(i32 5003, i32 -1)
%35 = call i32 @setfsuid(i32 5004)
%36 = call i32 @setfsuid(i32 -1)
%37 = call i32 @setfsgid(i32 5005)
%38 = call i32 @setfsgid(i32 -1)
ret i32 0
}