#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 */
int /*<<< orphan*/ _SC_GETGR_R_SIZE_MAX;
int /*<<< orphan*/ check_buff(char *, char *, int);
struct group *getgrgid(int /*<<< orphan*/);
char *malloc(size_t);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, size_t);
int sysconf(int /*<<< orphan*/);
char *create_groupname_from_gid(gid_t gid) {
  size_t buf_len = sysconf(_SC_GETGR_R_SIZE_MAX) * sizeof(char);
  char *uname_buff = malloc(buf_len);
  check_buff(uname_buff, "Failed to allocate buffer for permisson string.", 2);
  struct group *grp_st = getgrgid(gid);
  strncpy(uname_buff, grp_st->gr_name, buf_len);
}


x86 assembly (clang, -O0):
<create_groupname_from_gid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
cltq
shl    $0x0,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe75(%rip),%rsi
mov    $0x2,%edx
call   1050 <check_buff@plt>
mov    -0xc(%rbp),%edi
call   1040 <getgrgid@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_groupname_from_gid>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
call   1070 <sysconf@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbp
lea    0xe86(%rip),%rsi
mov    %rax,%rdi
mov    $0x2,%edx
call   1050 <check_buff@plt>
mov    %r14d,%edi
call   1040 <getgrgid@plt>
mov    (%rax),%esi
mov    %rbp,%rdi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
%struct.group = type { i32 }
@_SC_GETGR_R_SIZE_MAX = global i32 0
@.str = [48 x i8] c"Failed to allocate buffer for permisson string.\00"
define i8* @create_groupname_from_gid(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca %struct.group*
store i32 %0, i32* %3
%7 = load i32, i32* @_SC_GETGR_R_SIZE_MAX
%8 = call i32 @sysconf(i32 %7)
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 1
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = call i32 @check_buff(i8* %13, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 2)
%15 = load i32, i32* %3
%16 = call %struct.group* @getgrgid(i32 %15)
store %struct.group* %16, %struct.group** %6
%17 = load i8*, i8** %5
%18 = load %struct.group*, %struct.group** %6
%19 = getelementptr inbounds %struct.group, %struct.group* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load i64, i64* %4
%22 = call i32 @strncpy(i8* %17, i32 %20, i64 %21)
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
%struct.group = type { i32 }
@_SC_GETGR_R_SIZE_MAX = global i32 0
@.str = [48 x i8] c"Failed to allocate buffer for permisson string.\00"
define noalias i8* @create_groupname_from_gid(i32 %0) {
%2 = load i32, i32* @_SC_GETGR_R_SIZE_MAX
%3 = tail call i32 @sysconf(i32 %2)
%4 = sext i32 %3 to i64
%5 = tail call i8* @malloc(i64 %4)
%6 = tail call i32 @check_buff(i8* %5, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 2)
%7 = tail call %struct.group* @getgrgid(i32 %0)
%8 = getelementptr inbounds %struct.group, %struct.group* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @strncpy(i8* %5, i32 %9, i64 %4)
ret i8* undef
}