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

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct group *getgrgid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *groupname_from_groupid(gid_t gid) {
  struct group *grp;
  grp = getgrgid(gid);
  if (grp == NULL) {
    if (errno == 0) {
      fprintf(stderr, "Account Not Found.\n");
      return NULL;
    } else {
      fprintf(stderr, "Err. getgrgid() Failed.\n");
      return NULL;
    }
  } else
    return grp->gr_name;
}


x86 assembly (clang, -O0):
<groupname_from_groupid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1197 <groupname_from_groupid+0x77>
mov    0x2e8f(%rip),%rax
cmpq   $0x0,(%rax)
jne    1175 <groupname_from_groupid+0x55>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <groupname_from_groupid+0x82>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <groupname_from_groupid+0x82>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<groupname_from_groupid>:
push   %rax
call   1030 <getgrgid@plt>
test   %rax,%rax
je     1130 <groupname_from_groupid+0x10>
mov    (%rax),%rax
pop    %rcx
ret
mov    0x2ea1(%rip),%rax
cmpq   $0x0,(%rax)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
je     114f <groupname_from_groupid+0x2f>
lea    0xec7(%rip),%rsi
jmp    1156 <groupname_from_groupid+0x36>
lea    0xeaa(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.group = type { i8* }
@errno = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"Account Not Found.\0A\00"
@.str.1 = [25 x i8] c"Err. getgrgid() Failed.\0A\00"
define i8* @groupname_from_groupid(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.group*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call %struct.group* @getgrgid(i32 %5)
store %struct.group* %6, %struct.group** %4
%7 = load %struct.group*, %struct.group** %4
%8 = icmp eq %struct.group* %7, null
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %2
br label %22
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %22
18: ; preds = %1
%19 = load %struct.group*, %struct.group** %4
%20 = getelementptr inbounds %struct.group, %struct.group* %19, i32 0, i32 0
%21 = load i8*, i8** %20
store i8* %21, i8** %2
br label %22
22: ; preds = %18, %15, %12
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
%struct.group = type { i8* }
@errno = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"Account Not Found.\0A\00"
@.str.1 = [25 x i8] c"Err. getgrgid() Failed.\0A\00"
define i8* @groupname_from_groupid(i32 %0) {
%2 = tail call %struct.group* @getgrgid(i32 %0)
%3 = icmp eq %struct.group* %2, null
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
%7 = load i32, i32* @stderr
br i1 %6, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %15
10: ; preds = %4
%11 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %15
12: ; preds = %1
%13 = getelementptr inbounds %struct.group, %struct.group* %2, i64 0, i32 0
%14 = load i8*, i8** %13
br label %15
15: ; preds = %12, %10, %8
%16 = phi i8* [ null, %8 ], [ null, %10 ], [ %14, %12 ]
ret i8* %16
}