#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 group {
  int /*<<< orphan*/ gr_gid;
};
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
struct group *getgrnam(char *);
int /*<<< orphan*/ journal(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
gid_t get_daemon_group(void) {
  const struct group *grp;
  grp = getgrnam("daemon");
  if (!grp) {
    journal("Unable to find daemon group id: %s.\n", strerror(errno));
    return ((gid_t)(-1));
  }
  return grp->gr_gid;
}


x86 assembly (clang, -O0):
<get_daemon_group>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <getgrnam@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117b <get_daemon_group+0x4b>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    %eax,%esi
lea    0xe9d(%rip),%rdi
call   1050 <journal@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <get_daemon_group+0x54>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_daemon_group>:
push   %rax
lea    0xec8(%rip),%rdi
call   1030 <getgrnam@plt>
test   %rax,%rax
je     1146 <get_daemon_group+0x16>
mov    (%rax),%eax
pop    %rcx
ret
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xeac(%rip),%rdi
mov    %eax,%esi
call   1050 <journal@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.group = type { i32 }
@.str = [7 x i8] c"daemon\00"
@.str.1 = [37 x i8] c"Unable to find daemon group id: %s.\0A\00"
@errno = global i32 0
define i32 @get_daemon_group() {
%1 = alloca i32
%2 = alloca %struct.group*
%3 = call %struct.group* @getgrnam(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store %struct.group* %3, %struct.group** %2
%4 = load %struct.group*, %struct.group** %2
%5 = icmp ne %struct.group* %4, null
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 @strerror(i32 %7)
%9 = call i32 @journal(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %8)
store i32 -1, i32* %1
br label %14
10: ; preds = %0
%11 = load %struct.group*, %struct.group** %2
%12 = getelementptr inbounds %struct.group, %struct.group* %11, i32 0, i32 0
%13 = load i32, i32* %12
store i32 %13, i32* %1
br label %14
14: ; preds = %10, %6
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
%struct.group = type { i32 }
@.str = [7 x i8] c"daemon\00"
@.str.1 = [37 x i8] c"Unable to find daemon group id: %s.\0A\00"
@errno = global i32 0
define i32 @get_daemon_group() {
%1 = tail call %struct.group* @getgrnam(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq %struct.group* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @errno
%5 = tail call i32 @strerror(i32 %4)
%6 = tail call i32 @journal(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %10
7: ; preds = %0
%8 = getelementptr inbounds %struct.group, %struct.group* %1, i64 0, i32 0
%9 = load i32, i32* %8
br label %10
10: ; preds = %7, %3
%11 = phi i32 [ %9, %7 ], [ -1, %3 ]
ret i32 %11
}