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

/* Variables and functions */
int getresgid(int *, int *, int *);
int getresuid(int *, int *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int reportprivilege(char *message) {
  uid_t euid, ruid, suid;
  gid_t egid, rgid, sgid;
  int error;
  error = getresuid(&ruid, &euid, &suid);
  if (error) {
    perror("getresuid");
    return (error);
  }
  error = getresgid(&rgid, &egid, &sgid);
  if (error) {
    perror("getresgid");
    return (error);
  }
  if (message)
    printf("%s: ", message);
  printf("ruid: %d, euid: %d, suid: %d,     ", ruid, euid, suid);
  printf("rgid: %d, egid: %d, sgid: %d\n", rgid, egid, sgid);
  return (0);
}


x86 assembly (clang, -O0):
<reportprivilege>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <getresuid@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1181 <reportprivilege+0x41>
lea    0xe8f(%rip),%rdi
call   1060 <perror@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1208 <reportprivilege+0xc8>
lea    -0x24(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <getresgid@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11b6 <reportprivilege+0x76>
lea    0xe64(%rip),%rdi
call   1060 <perror@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1208 <reportprivilege+0xc8>
cmpq   $0x0,-0x10(%rbp)
je     11d3 <reportprivilege+0x93>
mov    -0x10(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reportprivilege>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0x10(%rsp),%rdi
lea    0x14(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1050 <getresuid@plt>
test   %eax,%eax
jne    11cd <reportprivilege+0x8d>
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1030 <getresgid@plt>
test   %eax,%eax
jne    11dd <reportprivilege+0x9d>
test   %r14,%r14
je     118e <reportprivilege+0x4e>
lea    0xe90(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xe78(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
mov    (%rsp),%ecx
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    %eax,%ebx
lea    0xe2a(%rip),%rdi
call   1060 <perror@plt>
jmp    11c3 <reportprivilege+0x83>
mov    %eax,%ebx
lea    0xe24(%rip),%rdi
call   1060 <perror@plt>
jmp    11c3 <reportprivilege+0x83>

LLVM IR (-O0):
@.str = [10 x i8] c"getresuid\00"
@.str.1 = [10 x i8] c"getresgid\00"
@.str.2 = [5 x i8] c"%s: \00"
@.str.3 = [35 x i8] c"ruid: %d, euid: %d, suid: %d, \00"
@.str.4 = [30 x i8] c"rgid: %d, egid: %d, sgid: %d\0A\00"
define i32 @reportprivilege(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
%11 = call i32 @getresuid(i32* %5, i32* %4, i32* %6)
store i32 %11, i32* %10
%12 = load i32, i32* %10
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %10
store i32 %16, i32* %2
br label %39
17: ; preds = %1
%18 = call i32 @getresgid(i32* %8, i32* %7, i32* %9)
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %10
store i32 %23, i32* %2
br label %39
24: ; preds = %17
%25 = load i8*, i8** %3
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i8*, i8** %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %5
%32 = load i32, i32* %4
%33 = load i32, i32* %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %32, i32 %33)
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = load i32, i32* %9
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %35, i32 %36, i32 %37)
store i32 0, i32* %2
br label %39
39: ; preds = %30, %21, %14
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [10 x i8] c"getresuid\00"
@.str.1 = [10 x i8] c"getresgid\00"
@.str.2 = [5 x i8] c"%s: \00"
@.str.3 = [35 x i8] c"ruid: %d, euid: %d, suid: %d, \00"
@.str.4 = [30 x i8] c"rgid: %d, egid: %d, sgid: %d\0A\00"
define i32 @reportprivilege(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%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 = bitcast i32* %7 to i8*
%14 = call i32 @getresuid(i32* %3, i32* %2, i32* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %36
18: ; preds = %1
%19 = call i32 @getresgid(i32* %6, i32* %5, i32* %7)
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %36
23: ; preds = %18
%24 = icmp eq i8* %0, null
br i1 %24, label %27, label %25
25: ; preds = %23
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %27
27: ; preds = %25, %23
%28 = load i32, i32* %3
%29 = load i32, i32* %2
%30 = load i32, i32* %4
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %29, i32 %30)
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = load i32, i32* %7
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 %33, i32 %34)
br label %36
36: ; preds = %27, %21, %16
%37 = phi i32 [ %14, %16 ], [ %19, %21 ], [ 0, %27 ]
ret i32 %37
}