#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 */
scalar_t__ alldigits(char const *);
int /*<<< orphan*/ atoi(char const *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ errorf(char *, char const *, int /*<<< orphan*/);
struct group *getgrnam(char const *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
gid_t find_gid(const char *g) {
  struct group *gr;
  if (alldigits(g))
    return atoi(g);
  if (!(gr = getgrnam(g)))
    errorf("Error finding group '%s': %s\n", g, strerror(errno));
  return gr->gr_gid;
}


x86 assembly (clang, -O0):
<find_gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <alldigits@plt>
cmp    $0x0,%rax
je     1180 <find_gid+0x30>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    11c8 <find_gid+0x78>
mov    -0x10(%rbp),%rdi
call   1040 <getgrnam@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11bf <find_gid+0x6f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe46(%rip),%rdi
call   1030 <errorf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_gid>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <alldigits@plt>
test   %rax,%rax
je     1170 <find_gid+0x20>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <atoi@plt>
mov    %rbx,%rdi
call   1040 <getgrnam@plt>
mov    %rax,%r14
test   %rax,%rax
jne    119f <find_gid+0x4f>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe6b(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <errorf@plt>
mov    (%r14),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.group = type { i32 }
@.str = [30 x i8] c"Error finding group '%s': %s\0A\00"
@errno = global i32 0
define i32 @find_gid(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.group*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @alldigits(i8* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @atoi(i8* %9)
store i32 %10, i32* %2
br label %24
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call %struct.group* @getgrnam(i8* %12)
store %struct.group* %13, %struct.group** %4
%14 = icmp ne %struct.group* %13, null
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @errorf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %18)
br label %20
20: ; preds = %15, %11
%21 = load %struct.group*, %struct.group** %4
%22 = getelementptr inbounds %struct.group, %struct.group* %21, i32 0, i32 0
%23 = load i32, i32* %22
store i32 %23, i32* %2
br label %24
24: ; preds = %20, %8
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
%struct.group = type { i32 }
@.str = [30 x i8] c"Error finding group '%s': %s\0A\00"
@errno = global i32 0
define i32 @find_gid(i8* %0) {
%2 = tail call i64 @alldigits(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @atoi(i8* %0)
br label %16
6: ; preds = %1
%7 = tail call %struct.group* @getgrnam(i8* %0)
%8 = icmp eq %struct.group* %7, null
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = load i32, i32* @errno
%11 = tail call i32 @strerror(i32 %10)
%12 = tail call i32 @errorf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %11)
br label %13
13: ; preds = %9, %6
%14 = getelementptr inbounds %struct.group, %struct.group* %7, i64 0, i32 0
%15 = load i32, i32* %14
br label %16
16: ; preds = %13, %4
%17 = phi i32 [ %5, %4 ], [ %15, %13 ]
ret i32 %17
}