#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 {
  int /*<<< orphan*/ pw_name;
  int /*<<< orphan*/ pw_gid;
};

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ perror(char *);
int setgid(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int setup_groups(const struct passwd *info) {
  if (setgid(info->pw_gid) == -1) {
    perror("setgid");
    syslog(LOG_ERR, "bad group ID `%d' for user `%s': %m\n", info->pw_gid,
           info->pw_name);
    closelog();
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setup_groups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1050 <setgid@plt>
cmp    $0xffffffff,%eax
jne    11a2 <setup_groups+0x62>
lea    0xe98(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xe7d(%rip),%rsi
call   1040 <syslog@plt>
mov    $0x0,%al
call   1030 <closelog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <setup_groups+0x69>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_groups>:
push   %rbx
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
call   1050 <setgid@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     1157 <setup_groups+0x17>
pop    %rbx
ret
lea    0xea2(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%ecx
mov    0x4(%rbx),%edx
lea    0xe8f(%rip),%rsi
call   1040 <syslog@plt>
xor    %eax,%eax
call   1030 <closelog@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i32, i32 }
@.str = [7 x i8] c"setgid\00"
@LOG_ERR = global i32 0
@.str.1 = [37 x i8] c"bad group ID `%d' for user `%s': %m\0A\00"
define i32 @setup_groups(%struct.passwd* %0) {
%2 = alloca i32
%3 = alloca %struct.passwd*
store %struct.passwd* %0, %struct.passwd** %3
%4 = load %struct.passwd*, %struct.passwd** %3
%5 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i32 0, i32 1
%6 = load i32, i32* %5
%7 = call i32 @setgid(i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @LOG_ERR
%12 = load %struct.passwd*, %struct.passwd** %3
%13 = getelementptr inbounds %struct.passwd, %struct.passwd* %12, i32 0, i32 1
%14 = load i32, i32* %13
%15 = load %struct.passwd*, %struct.passwd** %3
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @syslog(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %17)
%19 = call i32 (...) @closelog()
store i32 -1, i32* %2
br label %21
20: ; preds = %1
store i32 0, i32* %2
br label %21
21: ; preds = %20, %9
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.passwd = type { i32, i32 }
@.str = [7 x i8] c"setgid\00"
@LOG_ERR = global i32 0
@.str.1 = [37 x i8] c"bad group ID `%d' for user `%s': %m\0A\00"
define i32 @setup_groups(%struct.passwd* nocapture %0) {
%2 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 1
%3 = load i32, i32* %2
%4 = tail call i32 @setgid(i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @LOG_ERR
%9 = load i32, i32* %2
%10 = getelementptr inbounds %struct.passwd, %struct.passwd* %0, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i32 @syslog(i32 %8, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %11)
%13 = tail call i32 (...) @closelog()
br label %14
14: ; preds = %1, %6
%15 = phi i32 [ -1, %6 ], [ 0, %1 ]
ret i32 %15
}