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

/* Variables and functions */
struct group *getgrgid(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char const *_long_group(gid_t gid) {
  static char buf[12];
  struct group *grp;
  if ((grp = getgrgid(gid)) != NULL)
    return grp->gr_name;
  snprintf(buf, sizeof(buf), "%u", gid);
  return buf;
}


x86 assembly (clang, -O0):
<_long_group>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1151 <_long_group+0x31>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1177 <_long_group+0x57>
mov    -0xc(%rbp),%ecx
lea    0x2ed6(%rip),%rdi
mov    $0xc,%esi
lea    0xe99(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2ebe(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_long_group>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1030 <getgrgid@plt>
test   %rax,%rax
je     1134 <_long_group+0x14>
mov    (%rax),%rbx
jmp    1151 <_long_group+0x31>
lea    0x2ef6(%rip),%rbx
lea    0xebe(%rip),%rdx
mov    %rbx,%rdi
mov    $0xc,%esi
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.group = type { i8* }
@_long_group.buf = internal global [12 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
define i8* @_long_group(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 ne %struct.group* %6, null
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load %struct.group*, %struct.group** %4
%10 = getelementptr inbounds %struct.group, %struct.group* %9, i32 0, i32 0
%11 = load i8*, i8** %10
store i8* %11, i8** %2
br label %15
12: ; preds = %1
%13 = load i32, i32* %3
%14 = call i32 @snprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @_long_group.buf, i64 0, i64 0), i32 12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @_long_group.buf, i64 0, i64 0), i8** %2
br label %15
15: ; preds = %12, %8
%16 = load i8*, i8** %2
ret i8* %16
}

LLVM IR (-O2):
%struct.group = type { i8* }
@_long_group.buf = internal global [12 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
define i8* @_long_group(i32 %0) {
%2 = tail call %struct.group* @getgrgid(i32 %0)
%3 = icmp eq %struct.group* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = getelementptr inbounds %struct.group, %struct.group* %2, i64 0, i32 0
%6 = load i8*, i8** %5
br label %9
7: ; preds = %1
%8 = tail call i32 @snprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @_long_group.buf, i64 0, i64 0), i32 12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %9
9: ; preds = %7, %4
%10 = phi i8* [ %6, %4 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @_long_group.buf, i64 0, i64 0), %7 ]
ret i8* %10
}