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

/* Variables and functions */
struct group *getgrgid(long const);
struct group *getgrnam(char const *);
long strtol(char const *, char **, int);
struct group *getgroup(const char *groupname, const long grpuid) {
  long uidcheck = 0;
  char *pos = NULL;
  struct group *local_group = NULL;
  if ((groupname == NULL) && (grpuid != -1)) {
    if ((local_group = getgrgid(grpuid)) != NULL) {
      return local_group;
    } else {
      return NULL;
    }
  } else {
    uidcheck = strtol(groupname, &pos, 10);
    if ((local_group = getgrnam(groupname)) != NULL) {
      return local_group;
    } else if ((pos[0] == '\0') &&
               ((local_group = getgrgid(uidcheck)) != NULL)) {
      return local_group;
    } else {
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<getgroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119f <getgroup+0x6f>
cmpq   $0xffffffffffffffff,-0x18(%rbp)
je     119f <getgroup+0x6f>
mov    -0x18(%rbp),%rdi
call   1030 <getgrgid@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1192 <getgroup+0x62>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1224 <getgroup+0xf4>
movq   $0x0,-0x8(%rbp)
jmp    1224 <getgroup+0xf4>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getgrnam@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11d9 <getgroup+0xa9>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1224 <getgroup+0xf4>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    120d <getgroup+0xdd>
mov    -0x20(%rbp),%rdi
call   1030 <getgrgid@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     120d <getgroup+0xdd>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1224 <getgroup+0xf4>
jmp    1212 <getgroup+0xe2>
jmp    1217 <getgroup+0xe7>
jmp    121c <getgroup+0xec>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getgroup>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movq   $0x0,(%rsp)
test   %rdi,%rdi
jne    1159 <getgroup+0x29>
cmp    $0xffffffffffffffff,%rsi
je     1159 <getgroup+0x29>
mov    %rsi,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <getgrgid@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <getgrnam@plt>
test   %rax,%rax
jne    1191 <getgroup+0x61>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    118f <getgroup+0x5f>
mov    %r14,%rdi
call   1030 <getgrgid@plt>
test   %rax,%rax
jne    1191 <getgroup+0x61>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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