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

/* Variables and functions */
int /*<<< orphan*/ errx(int, char *, char const *);
struct group *getgrnam(char const *);
int getnum(char const *, int /*<<< orphan*/ *);
gid_t getgroup(const char *group) {
  uintmax_t num;
  struct group *gp;
  if ((gp = getgrnam(group)) != NULL)
    return gp->gr_gid;
  if (getnum(group, &num) == -1)
    errx(1, "no such group `%s'", group);
  return (gid_t)num;
}


x86 assembly (clang, -O0):
<getgroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getgrnam@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1161 <getgroup+0x31>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1192 <getgroup+0x62>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <getnum@plt>
cmp    $0xffffffff,%eax
jne    118c <getgroup+0x5c>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe79(%rip),%rsi
call   1040 <errx@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getgroup>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <getgrnam@plt>
test   %rax,%rax
je     1146 <getgroup+0x16>
mov    %rax,%rbx
jmp    116f <getgroup+0x3f>
lea    0x4(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <getnum@plt>
cmp    $0xffffffff,%eax
jne    116f <getgroup+0x3f>
lea    0xe9e(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
call   1040 <errx@plt>
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.group = type { i32 }
@.str = [19 x i8] c"no such group `%s'\00"
define i32 @getgroup(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.group*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call %struct.group* @getgrnam(i8* %6)
store %struct.group* %7, %struct.group** %5
%8 = icmp ne %struct.group* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load %struct.group*, %struct.group** %5
%11 = getelementptr inbounds %struct.group, %struct.group* %10, i32 0, i32 0
%12 = load i32, i32* %11
store i32 %12, i32* %2
br label %22
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @getnum(i8* %14, i32* %4)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = call i32 @errx(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %13
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %22
22: ; preds = %20, %9
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.group = type { i32 }
@.str = [19 x i8] c"no such group `%s'\00"
define i32 @getgroup(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call %struct.group* @getgrnam(i8* %0)
%5 = icmp eq %struct.group* %4, null
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.group, %struct.group* %4, i64 0, i32 0
br label %13
8: ; preds = %1
%9 = call i32 @getnum(i8* %0, i32* %2)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @errx(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %8, %11, %6
%14 = phi i32* [ %7, %6 ], [ %2, %11 ], [ %2, %8 ]
%15 = load i32, i32* %14
ret i32 %15
}