#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 */
struct passwd {
  scalar_t__ pw_uid;
  scalar_t__ pw_gid;
};

/* Variables and functions */
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ setgid(scalar_t__);
scalar_t__ setuid(scalar_t__);
void set_user(struct passwd *entry) {
  if (setgid(entry->pw_gid) && entry->pw_gid) {
    perror("setgid");
    _exit(1);
  }
  if (setuid(entry->pw_uid) && entry->pw_uid) {
    perror("setuid");
    _exit(1);
  }
}


x86 assembly (clang, -O0):
<set_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <setgid@plt>
cmp    $0x0,%rax
je     1188 <set_user+0x48>
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1188 <set_user+0x48>
lea    0xe87(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1060 <setuid@plt>
cmp    $0x0,%rax
je     11c2 <set_user+0x82>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11c2 <set_user+0x82>
lea    0xe54(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_user>:
push   %rbx
mov    %rdi,%rbx
mov    0x8(%rdi),%rdi
call   1040 <setgid@plt>
test   %rax,%rax
je     1159 <set_user+0x19>
cmpq   $0x0,0x8(%rbx)
jne    116e <set_user+0x2e>
mov    (%rbx),%rdi
call   1060 <setuid@plt>
test   %rax,%rax
je     116c <set_user+0x2c>
cmpq   $0x0,(%rbx)
jne    1177 <set_user+0x37>
pop    %rbx
ret
lea    0xe8b(%rip),%rdi
jmp    117e <set_user+0x3e>
lea    0xe89(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i64, i64 }
@.str = [7 x i8] c"setgid\00"
@.str.1 = [7 x i8] c"setuid\00"
define void @set_user(%struct.passwd* %0) {
%2 = alloca %struct.passwd*
store %struct.passwd* %0, %struct.passwd** %2
%3 = load %struct.passwd*, %struct.passwd** %2
%4 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i32 0, i32 1
%5 = load i64, i64* %4
%6 = call i64 @setgid(i64 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %1
%9 = load %struct.passwd*, %struct.passwd** %2
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %9, i32 0, i32 1
%11 = load i64, i64* %10
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @_exit(i32 1)
unreachable
16: ; preds = %8, %1
%17 = load %struct.passwd*, %struct.passwd** %2
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = call i64 @setuid(i64 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %16
%23 = load %struct.passwd*, %struct.passwd** %2
%24 = getelementptr inbounds %struct.passwd, %struct.passwd* %23, i32 0, i32 0
%25 = load i64, i64* %24
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @_exit(i32 1)
unreachable
30: ; preds = %22, %16
ret void
}

LLVM IR (-O2):
%struct.passwd = type { i64, i64 }
@.str = [7 x i8] c"setgid\00"
@.str.1 = [7 x i8] c"setuid\00"
define void @set_user(%struct.passwd* nocapture %0) {
%2 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 1
%3 = load i64, i64* %2
%4 = tail call i64 @setgid(i64 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = load i64, i64* %2
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @_exit(i32 1)
unreachable
12: ; preds = %6, %1
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 0
%14 = load i64, i64* %13
%15 = tail call i64 @setuid(i64 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %12
%18 = load i64, i64* %13
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @_exit(i32 1)
unreachable
23: ; preds = %17, %12
ret void
}