#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 */
struct group *getgrnam(char *);
int strtol(char *, char **, int);
int group2gid(int *gid, char *group) {
  char *tmp;
  struct group *gr_entry;
  if (group) {
    *gid = strtol(group, &tmp, 10);
    if ((tmp == 0) || (*tmp)) {
      gr_entry = getgrnam(group);
      if (gr_entry == 0) {
        goto error;
      }
      *gid = gr_entry->gr_gid;
    }
    return 0;
  }
error:
  return -1;
}


x86 assembly (clang, -O0):
<group2gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a5 <group2gid+0x85>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1170 <group2gid+0x50>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1199 <group2gid+0x79>
mov    -0x18(%rbp),%rdi
call   1040 <getgrnam@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118d <group2gid+0x6d>
jmp    11aa <group2gid+0x8a>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11b1 <group2gid+0x91>
jmp    11aa <group2gid+0x8a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<group2gid>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%ebp
test   %rsi,%rsi
je     1170 <group2gid+0x50>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,(%r14)
mov    0x8(%rsp),%rax
test   %rax,%rax
je     115c <group2gid+0x3c>
cmpb   $0x0,(%rax)
je     116e <group2gid+0x4e>
mov    %rbx,%rdi
call   1040 <getgrnam@plt>
test   %rax,%rax
je     1170 <group2gid+0x50>
mov    (%rax),%eax
mov    %eax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.group = type { i32 }
define i32 @group2gid(i32* nocapture writeonly %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i8* %1, null
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = call i32 @strtol(i8* %1, i8** %3, i32 10)
store i32 %7, i32* %0
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %10, %6
%14 = tail call %struct.group* @getgrnam(i8* %1)
%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* %0
br label %19
19: ; preds = %13, %2, %10, %16
%20 = phi i32 [ 0, %16 ], [ 0, %10 ], [ -1, %2 ], [ -1, %13 ]
ret i32 %20
}