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

/* Variables and functions */
int /*<<< orphan*/ child_log(char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int setresgid(int, int, int);
scalar_t__ strerror(int /*<<< orphan*/);
void do_setresgid(int gid) {
  int result = setresgid(gid, gid, gid);
  if (result == -1) {
    char *msg = (char *)strerror(errno);
    child_log("Child: An error has occurred during the setresgid 	"
              "		  call: %d\n%s\n",
              errno, msg);
    child_log("This probably means that the process was 		"
              "	  not privileged enough to make this call\n");
    exit(-1);
  }
  child_log("Child: Successful setresgid\n");
}


x86 assembly (clang, -O0):
<do_setresgid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1040 <setresgid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11ab <do_setresgid+0x6b>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <child_log@plt>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <child_log@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1030 <child_log@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_setresgid>:
push   %rbx
mov    %edi,%esi
mov    %edi,%edx
call   1040 <setresgid@plt>
cmp    $0xffffffff,%eax
je     115e <do_setresgid+0x1e>
lea    0xf45(%rip),%rdi
xor    %eax,%eax
pop    %rbx
jmp    1030 <child_log@plt>
mov    0x2e7b(%rip),%rbx
mov    (%rbx),%edi
call   1060 <strerror@plt>
mov    (%rbx),%esi
lea    0xe8b(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <child_log@plt>
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1030 <child_log@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [68 x i8] c"Child: An error has occurred during the setresgid \09\09\09 call: %d\0A%s\0A\00"
@.str.1 = [87 x i8] c"This probably means that the process was \09\09\09 not privileged enough to make this call\0A\00"
@.str.2 = [29 x i8] c"Child: Successful setresgid\0A\00"
define void @do_setresgid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @setresgid(i32 %5, i32 %6, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %20
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = call i64 @strerror(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load i32, i32* @errno
%16 = load i8*, i8** %4
%17 = call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %16)
%18 = call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %1
%21 = call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [68 x i8] c"Child: An error has occurred during the setresgid \09\09\09 call: %d\0A%s\0A\00"
@.str.1 = [87 x i8] c"This probably means that the process was \09\09\09 not privileged enough to make this call\0A\00"
@.str.2 = [29 x i8] c"Child: Successful setresgid\0A\00"
define void @do_setresgid(i32 %0) {
%2 = tail call i32 @setresgid(i32 %0, i32 %0, i32 %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = load i32, i32* @errno
%6 = tail call i64 @strerror(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = load i32, i32* @errno
%9 = tail call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %7)
%10 = tail call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %1
%13 = tail call i32 (i8*, ...) @child_log(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
ret void
}