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

/* Variables and functions */
int /*<<< orphan*/ die(char *);
scalar_t__ setgid(scalar_t__);
scalar_t__ setuid(scalar_t__);
void setuidgid(uid_t uid, gid_t gid) {
  if (gid)
    if (setgid(gid))
      die("Could not set GID");
  if (uid)
    if (setuid(uid))
      die("Could not set UID");
}


x86 assembly (clang, -O0):
<setuidgid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116f <setuidgid+0x3f>
mov    -0x10(%rbp),%rdi
call   1030 <setgid@plt>
cmp    $0x0,%rax
je     116a <setuidgid+0x3a>
lea    0xe9b(%rip),%rdi
call   1040 <die@plt>
jmp    116f <setuidgid+0x3f>
cmpq   $0x0,-0x8(%rbp)
je     119e <setuidgid+0x6e>
mov    -0x8(%rbp),%rdi
call   1050 <setuid@plt>
cmp    $0x0,%rax
je     1199 <setuidgid+0x69>
lea    0xe7e(%rip),%rdi
call   1040 <die@plt>
jmp    119e <setuidgid+0x6e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setuidgid>:
push   %rbx
mov    %rdi,%rbx
test   %rsi,%rsi
je     1152 <setuidgid+0x22>
mov    %rsi,%rdi
call   1030 <setgid@plt>
test   %rax,%rax
je     1152 <setuidgid+0x22>
lea    0xeb3(%rip),%rdi
call   1040 <die@plt>
test   %rbx,%rbx
je     1171 <setuidgid+0x41>
mov    %rbx,%rdi
call   1050 <setuid@plt>
test   %rax,%rax
je     1171 <setuidgid+0x41>
lea    0xea7(%rip),%rdi
pop    %rbx
jmp    1040 <die@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Could not set GID\00"
@.str.1 = [18 x i8] c"Could not set UID\00"
define void @setuidgid(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%5 = load i64, i64* %4
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = load i64, i64* %4
%9 = call i64 @setgid(i64 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
br label %14
14: ; preds = %13, %2
%15 = load i64, i64* %3
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i64, i64* %3
%19 = call i64 @setuid(i64 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
br label %24
24: ; preds = %23, %14
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"Could not set GID\00"
@.str.1 = [18 x i8] c"Could not set UID\00"
define void @setuidgid(i64 %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = tail call i64 @setgid(i64 %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %4, %7, %2
%10 = icmp eq i64 %0, 0
br i1 %10, label %16, label %11
11: ; preds = %9
%12 = tail call i64 @setuid(i64 %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %11, %14, %9
ret void
}