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

/* Variables and functions */
struct group *getgrgid(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
const char *get_group_name(gid_t gid) {
  static char name[128];
  struct group *grp;
  if ((grp = getgrgid(gid)) == NULL) {
    return NULL;
  }
  strncpy(name, grp->gr_name, 128);
  name[128 - 1] = '\0';
  return name;
}


x86 assembly (clang, -O0):
<get_group_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    114e <get_group_name+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    1177 <get_group_name+0x57>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0x2ee5(%rip),%rdi
mov    $0x80,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x2f53(%rip)
lea    0x2ecd(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_group_name>:
push   %rbx
call   1040 <getgrgid@plt>
test   %rax,%rax
je     114a <get_group_name+0x2a>
mov    (%rax),%esi
lea    0x2f0c(%rip),%rbx
mov    %rbx,%rdi
mov    $0x80,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x2f77(%rip)
jmp    114c <get_group_name+0x2c>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.group = type { i32 }
@get_group_name.name = internal global [128 x i8] zeroinitializer
define i8* @get_group_name(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 = icmp eq %struct.group* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* null, i8** %2
br label %14
9: ; preds = %1
%10 = load %struct.group*, %struct.group** %4
%11 = getelementptr inbounds %struct.group, %struct.group* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @strncpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_group_name.name, i64 0, i64 0), i32 %12, i32 128)
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_group_name.name, i64 0, i64 127)
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_group_name.name, i64 0, i64 0), i8** %2
br label %14
14: ; preds = %9, %8
%15 = load i8*, i8** %2
ret i8* %15
}

LLVM IR (-O2):
%struct.group = type { i32 }
@get_group_name.name = internal global [128 x i8] zeroinitializer
define i8* @get_group_name(i32 %0) {
%2 = tail call %struct.group* @getgrgid(i32 %0)
%3 = icmp eq %struct.group* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.group, %struct.group* %2, i64 0, i32 0
%6 = load i32, i32* %5
%7 = tail call i32 @strncpy(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_group_name.name, i64 0, i64 0), i32 %6, i32 128)
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_group_name.name, i64 0, i64 127)
br label %8
8: ; preds = %1, %4
%9 = phi i8* [ getelementptr inbounds ([128 x i8], [128 x i8]* @get_group_name.name, i64 0, i64 0), %4 ], [ null, %1 ]
ret i8* %9
}