#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*/ atoi(char const *);
struct group *getgrnam(char const *);
scalar_t__ isdigit(char const);
int get_gid(const char group[], gid_t *gid) {
  if (isdigit(group[0])) {
    *gid = atoi(group);
  } else {
    struct group *g;
    g = getgrnam(group);
    if (g == NULL)
      return 1;
    *gid = g->gr_gid;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     116c <get_gid+0x3c>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    119c <get_gid+0x6c>
mov    -0x10(%rbp),%rdi
call   1040 <getgrnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1190 <get_gid+0x60>
movl   $0x1,-0x4(%rbp)
jmp    11a3 <get_gid+0x73>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_gid>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     1151 <get_gid+0x21>
call   1050 <atoi@plt>
jmp    115d <get_gid+0x2d>
call   1040 <getgrnam@plt>
test   %rax,%rax
je     116a <get_gid+0x3a>
mov    (%rax),%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%eax
jmp    1162 <get_gid+0x32>

LLVM IR (-O0):
%struct.group = type { i32 }
define i32 @get_gid(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.group*
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = call i64 @isdigit(i8 signext %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @atoi(i8* %13)
%15 = load i32*, i32** %5
store i32 %14, i32* %15
br label %27
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call %struct.group* @getgrnam(i8* %17)
store %struct.group* %18, %struct.group** %6
%19 = load %struct.group*, %struct.group** %6
%20 = icmp eq %struct.group* %19, null
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 1, i32* %3
br label %28
22: ; preds = %16
%23 = load %struct.group*, %struct.group** %6
%24 = getelementptr inbounds %struct.group, %struct.group* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = load i32*, i32** %5
store i32 %25, i32* %26
br label %27
27: ; preds = %22, %12
store i32 0, i32* %3
br label %28
28: ; preds = %27, %21
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.group = type { i32 }
define i32 @get_gid(i8* %0, i32* nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = tail call i64 @isdigit(i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @atoi(i8* %0)
br label %14
8: ; preds = %2
%9 = tail call %struct.group* @getgrnam(i8* %0)
%10 = icmp eq %struct.group* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = getelementptr inbounds %struct.group, %struct.group* %9, i64 0, i32 0
%13 = load i32, i32* %12
br label %14
14: ; preds = %11, %6
%15 = phi i32 [ %7, %6 ], [ %13, %11 ]
store i32 %15, i32* %1
br label %16
16: ; preds = %14, %8
%17 = phi i32 [ 1, %8 ], [ 0, %14 ]
ret i32 %17
}