#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;
};
typedef int gid_t;

/* Variables and functions */
struct group *getgrnam(char const *);
long strtol(char const *, char **, int);
gid_t parse_gid(const char *group, gid_t *g) {
  char *v;
  long l;
  l = strtol(group, &v, 10);
  if (v && !*v) {
    *g = (gid_t)l;
    return 1;
  } else {
    struct group *grp = getgrnam(group);
    if (grp) {
      *g = grp->gr_gid;
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1176 <parse_gid+0x56>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1176 <parse_gid+0x56>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11b2 <parse_gid+0x92>
mov    -0x10(%rbp),%rdi
call   1040 <getgrnam@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11a6 <parse_gid+0x86>
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11b2 <parse_gid+0x92>
jmp    11ab <parse_gid+0x8b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_gid>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     1145 <parse_gid+0x25>
cmpb   $0x0,(%rcx)
je     1164 <parse_gid+0x44>
mov    %rbx,%rdi
call   1040 <getgrnam@plt>
mov    %rax,%rcx
test   %rax,%rax
je     115a <parse_gid+0x3a>
mov    (%rcx),%eax
mov    %eax,(%r14)
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    116c <parse_gid+0x4c>
mov    %eax,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.group = type { i32 }
define i32 @parse_gid(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = trunc i64 %5 to i32
store i32 %12, i32* %1
br label %22
13: ; preds = %8, %2
%14 = tail call %struct.group* @getgrnam(i8* %0)
%15 = icmp eq %struct.group* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = getelementptr inbounds %struct.group, %struct.group* %14, i64 0, i32 0
%18 = load i32, i32* %17
store i32 %18, i32* %1
br label %19
19: ; preds = %13, %16
%20 = xor i1 %15, true
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %19, %11
%23 = phi i32 [ 1, %11 ], [ %21, %19 ]
ret i32 %23
}