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

/* Variables and functions */
char *_utoa(int /*<<< orphan*/);
struct group *getgrgid(int /*<<< orphan*/);
char *utils_strdup(scalar_t__ *);
char *linux_map_gid(gid_t gid) {
  char *name = NULL;
  struct group *grp = getgrgid(gid);
  if (grp && grp->gr_name && *grp->gr_name) {
    name = utils_strdup(grp->gr_name);
  } else {
    name = _utoa(gid);
  }
  return name;
}


x86 assembly (clang, -O0):
<linux_map_gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118e <linux_map_gid+0x5e>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     118e <linux_map_gid+0x5e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,(%rax)
je     118e <linux_map_gid+0x5e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <utils_strdup@plt>
mov    %rax,-0x10(%rbp)
jmp    119a <linux_map_gid+0x6a>
mov    -0x4(%rbp),%edi
call   1050 <_utoa@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linux_map_gid>:
push   %rbx
mov    %edi,%ebx
call   1040 <getgrgid@plt>
test   %rax,%rax
je     1151 <linux_map_gid+0x21>
mov    (%rax),%rdi
test   %rdi,%rdi
je     1151 <linux_map_gid+0x21>
cmpq   $0x0,(%rdi)
je     1151 <linux_map_gid+0x21>
pop    %rbx
jmp    1030 <utils_strdup@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1050 <_utoa@plt>

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

LLVM IR (-O2):
%struct.group = type { i64* }
define i8* @linux_map_gid(i32 %0) {
%2 = tail call %struct.group* @getgrgid(i32 %0)
%3 = icmp eq %struct.group* %2, null
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.group, %struct.group* %2, i64 0, i32 0
%6 = load i64*, i64** %5
%7 = icmp eq i64* %6, null
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = load i64, i64* %6
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i8* @utils_strdup(i64* %6)
br label %15
13: ; preds = %8, %4, %1
%14 = tail call i8* @_utoa(i32 %0)
br label %15
15: ; preds = %13, %11
%16 = phi i8* [ %12, %11 ], [ %14, %13 ]
ret i8* %16
}