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

/* Variables and functions */
struct group const *getgrgid(int /*<<< orphan*/);
struct group const *getgrnam(char const *);
long strtol(char const *, char **, int);
const struct group *find_group(const char *input) {
  if (!input || !input[0])
    return NULL;
  char *endptr;
  long int i = strtol(input, &endptr, 10);
  if (*endptr == '\0') {
    return getgrgid((gid_t)i);
  } else {
    return getgrnam(input);
  }
}


x86 assembly (clang, -O0):
<find_group>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1154 <find_group+0x24>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1161 <find_group+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11a8 <find_group+0x78>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    119b <find_group+0x6b>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1030 <getgrgid@plt>
mov    %rax,-0x8(%rbp)
jmp    11a8 <find_group+0x78>
mov    -0x10(%rbp),%rdi
call   1050 <getgrnam@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_group>:
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     1168 <find_group+0x38>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1168 <find_group+0x38>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
je     116c <find_group+0x3c>
mov    %rbx,%rdi
call   1050 <getgrnam@plt>
jmp    1173 <find_group+0x43>
xor    %eax,%eax
jmp    1173 <find_group+0x43>
mov    %eax,%edi
call   1030 <getgrgid@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

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