#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 gr_gid;
};

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
struct group *getgrnam(char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int groupname2gid(const char *name) {
  struct group *grp;
  errno = 0;
  grp = getgrnam(name);
  if (grp == NULL) {
    if (errno)
      perror("Error: while converting group name to GID");
    else
      fprintf(stderr, "Error: unknown group %s\n", name);
    exit(1);
  }
  return grp->gr_gid;
}


x86 assembly (clang, -O0):
<groupname2gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e85(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <getgrnam@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b7 <groupname2gid+0x77>
mov    0x2e5f(%rip),%rax
cmpq   $0x0,(%rax)
je     1194 <groupname2gid+0x54>
lea    0xe76(%rip),%rdi
call   1050 <perror@plt>
jmp    11ad <groupname2gid+0x6d>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<groupname2gid>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e8a(%rip),%r14
movq   $0x0,(%r14)
call   1040 <getgrnam@plt>
test   %rax,%rax
je     1169 <groupname2gid+0x29>
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
cmpq   $0x0,(%r14)
je     1185 <groupname2gid+0x45>
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.group = type { i32 }
@errno = global i64 0
@.str = [42 x i8] c"Error: while converting group name to GID\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Error: unknown group %s\0A\00"
define i32 @groupname2gid(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.group*
store i8* %0, i8** %2
store i64 0, i64* @errno
%4 = load i8*, i8** %2
%5 = call %struct.group* @getgrnam(i8* %4)
store %struct.group* %5, %struct.group** %3
%6 = load %struct.group*, %struct.group** %3
%7 = icmp eq %struct.group* %6, null
br i1 %7, label %8, label %19
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %17
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %2
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %13, %11
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %1
%20 = load %struct.group*, %struct.group** %3
%21 = getelementptr inbounds %struct.group, %struct.group* %20, i32 0, i32 0
%22 = load i32, i32* %21
ret i32 %22
}

LLVM IR (-O2):
%struct.group = type { i32 }
@errno = global i64 0
@.str = [42 x i8] c"Error: while converting group name to GID\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Error: unknown group %s\0A\00"
define i32 @groupname2gid(i8* %0) {
store i64 0, i64* @errno
%2 = tail call %struct.group* @getgrnam(i8* %0)
%3 = icmp eq %struct.group* %2, null
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %12
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %9, %7
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = getelementptr inbounds %struct.group, %struct.group* %2, i64 0, i32 0
%16 = load i32, i32* %15
ret i32 %16
}