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

/* Variables and functions */
int /*<<< orphan*/ _setgroups(int, int *);
int /*<<< orphan*/ _unlink(char *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ change_fsid(int, int, int, int);
char *create_file(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ diod_log_init(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ geteuid();
int /*<<< orphan*/ msg(char *, ...);
int read_file(char *);
int main(int argc, char *argv[]) {
  char *path;
  gid_t gids[] = {101};
  diod_log_init(argv[0]);
  assert(geteuid() == 0);
  _setgroups(0, NULL);
  msg("supplemental groups cleared");
  assert(geteuid() == 0);
  path = create_file(0, 101, 0440);
  change_fsid(0, 0, 100, 100);
  assert(!read_file(path));
  change_fsid(100, 100, 100, 101);
  assert(read_file(path));
  change_fsid(100, 101, 100, 100);
  assert(!read_file(path));
  _setgroups(1, gids);
  msg("%d added to supplemental groups", gids[0]);
  assert(read_file(path));
  _setgroups(0, NULL);
  msg("supplemental groups cleared");
  assert(!read_file(path));
  change_fsid(100, 100, 0, 0);
  _unlink(path);
  msg("test complete");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe44(%rip),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <diod_log_init@plt>
mov    $0x0,%al
call   1030 <geteuid@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <_setgroups@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   10c0 <msg@plt>
mov    $0x0,%al
call   1030 <geteuid@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %edi,%edi
mov    $0x65,%esi
mov    $0x120,%edx
call   1090 <create_file@plt>
mov    %rax,-0x18(%rbp)
xor    %esi,%esi
mov    $0x64,%ecx
mov    %esi,%edi
mov    %ecx,%edx
call   1060 <change_fsid@plt>
mov    -0x18(%rbp),%rdi
call   1050 <read_file@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x64,%edx
mov    $0x65,%ecx
mov    %edx,%edi
mov    %edx,%esi
call   1060 <change_fsid@plt>
mov    -0x18(%rbp),%rdi
call   1050 <read_file@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    $0x64,%ecx
mov    $0x65,%esi
mov    %ecx,%edi
mov    %ecx,%edx
call   1060 <change_fsid@plt>
mov    -0x18(%rbp),%rdi
call   1050 <read_file@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x1c(%rbp),%rsi
mov    $0x1,%edi
call   1070 <_setgroups@plt>
mov    -0x1c(%rbp),%esi
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   10c0 <msg@plt>
mov    -0x18(%rbp),%rdi
call   1050 <read_file@plt>
mov    %eax,%edi
call   1040 <assert@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <_setgroups@plt>
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   10c0 <msg@plt>
mov    -0x18(%rbp),%rdi
call   1050 <read_file@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x64,%esi
xor    %ecx,%ecx
mov    %esi,%edi
mov    %ecx,%edx
call   1060 <change_fsid@plt>
mov    -0x18(%rbp),%rdi
call   1080 <_unlink@plt>
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   10c0 <msg@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movl   $0x65,0x4(%rsp)
mov    (%rsi),%rdi
call   10b0 <diod_log_init@plt>
xor    %eax,%eax
call   1030 <geteuid@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1070 <_setgroups@plt>
lea    0xe27(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   10c0 <msg@plt>
xor    %eax,%eax
call   1030 <geteuid@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
mov    $0x65,%esi
mov    $0x120,%edx
call   1090 <create_file@plt>
mov    %rax,%rbx
xor    %edi,%edi
xor    %esi,%esi
mov    $0x64,%edx
mov    $0x64,%ecx
call   1060 <change_fsid@plt>
mov    %rbx,%rdi
call   1050 <read_file@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    $0x64,%edi
mov    $0x64,%esi
mov    $0x64,%edx
mov    $0x65,%ecx
call   1060 <change_fsid@plt>
mov    %rbx,%rdi
call   1050 <read_file@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    $0x64,%edi
mov    $0x65,%esi
mov    $0x64,%edx
mov    $0x64,%ecx
call   1060 <change_fsid@plt>
mov    %rbx,%rdi
call   1050 <read_file@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
lea    0x4(%rsp),%rsi
mov    $0x1,%edi
call   1070 <_setgroups@plt>
mov    0x4(%rsp),%esi
lea    0xd78(%rip),%rdi
xor    %eax,%eax
call   10c0 <msg@plt>
mov    %rbx,%rdi
call   1050 <read_file@plt>
mov    %eax,%edi
call   1040 <assert@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1070 <_setgroups@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   10c0 <msg@plt>
mov    %rbx,%rdi
call   1050 <read_file@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    $0x64,%edi
mov    $0x64,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <change_fsid@plt>
mov    %rbx,%rdi
call   1080 <_unlink@plt>
lea    0xd38(%rip),%rdi
xor    %eax,%eax
call   10c0 <msg@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.gids = [1 x i32] [i32 101]
@.str = [28 x i8] c"supplemental groups cleared\00"
@.str.1 = [32 x i8] c"%d added to supplemental groups\00"
@.str.2 = [14 x i8] c"test complete\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [1 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [1 x i32]* %7 to i8*
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 @diod_log_init(i8* %11)
%13 = call i64 (...) @geteuid()
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @_setgroups(i32 0, i32* null)
%18 = call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%19 = call i64 (...) @geteuid()
%20 = icmp eq i64 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = call i8* @create_file(i32 0, i32 101, i32 288)
store i8* %23, i8** %6
%24 = call i32 @change_fsid(i32 0, i32 0, i32 100, i32 100)
%25 = load i8*, i8** %6
%26 = call i32 @read_file(i8* %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = call i32 @change_fsid(i32 100, i32 100, i32 100, i32 101)
%32 = load i8*, i8** %6
%33 = call i32 @read_file(i8* %32)
%34 = call i32 @assert(i32 %33)
%35 = call i32 @change_fsid(i32 100, i32 101, i32 100, i32 100)
%36 = load i8*, i8** %6
%37 = call i32 @read_file(i8* %36)
%38 = icmp ne i32 %37, 0
%39 = xor i1 %38, true
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 0
%43 = call i32 @_setgroups(i32 1, i32* %42)
%44 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 0
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = load i8*, i8** %6
%48 = call i32 @read_file(i8* %47)
%49 = call i32 @assert(i32 %48)
%50 = call i32 @_setgroups(i32 0, i32* null)
%51 = call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%52 = load i8*, i8** %6
%53 = call i32 @read_file(i8* %52)
%54 = icmp ne i32 %53, 0
%55 = xor i1 %54, true
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = call i32 @change_fsid(i32 100, i32 100, i32 0, i32 0)
%59 = load i8*, i8** %6
%60 = call i32 @_unlink(i8* %59)
%61 = call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%62 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [28 x i8] c"supplemental groups cleared\00"
@.str.1 = [32 x i8] c"%d added to supplemental groups\00"
@.str.2 = [14 x i8] c"test complete\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1 x i32]
%4 = bitcast [1 x i32]* %3 to i8*
%5 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
store i32 101, i32* %5
%6 = load i8*, i8** %1
%7 = tail call i32 @diod_log_init(i8* %6)
%8 = tail call i64 (...) @geteuid()
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i32 @_setgroups(i32 0, i32* null)
%13 = tail call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%14 = tail call i64 (...) @geteuid()
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i8* @create_file(i32 0, i32 101, i32 288)
%19 = tail call i32 @change_fsid(i32 0, i32 0, i32 100, i32 100)
%20 = tail call i32 @read_file(i8* %18)
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = tail call i32 @change_fsid(i32 100, i32 100, i32 100, i32 101)
%25 = tail call i32 @read_file(i8* %18)
%26 = tail call i32 @assert(i32 %25)
%27 = tail call i32 @change_fsid(i32 100, i32 101, i32 100, i32 100)
%28 = tail call i32 @read_file(i8* %18)
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = tail call i32 @assert(i32 %30)
%32 = call i32 @_setgroups(i32 1, i32* %5)
%33 = load i32, i32* %5
%34 = call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = call i32 @read_file(i8* %18)
%36 = call i32 @assert(i32 %35)
%37 = call i32 @_setgroups(i32 0, i32* null)
%38 = call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%39 = call i32 @read_file(i8* %18)
%40 = icmp eq i32 %39, 0
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = call i32 @change_fsid(i32 100, i32 100, i32 0, i32 0)
%44 = call i32 @_unlink(i8* %18)
%45 = call i32 (i8*, ...) @msg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 0)
unreachable
}