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

/* Variables and functions */
struct group *getgrgid(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
char *gid_to_name(gid_t gid) {
  struct group *gr = getgrgid(gid);
  static char tmp[64];
  if (!gr)
    sprintf(tmp, "%d", gid);
  else
    strncpy(tmp, gr->gr_name, sizeof(tmp));
  return tmp;
}


x86 assembly (clang, -O0):
<gid_to_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <getgrgid@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <gid_to_name+0x3d>
mov    -0x4(%rbp),%edx
lea    0x2ef4(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <sprintf@plt>
jmp    1184 <gid_to_name+0x54>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0x2ed6(%rip),%rdi
mov    $0x40,%edx
call   1030 <strncpy@plt>
lea    0x2ec5(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gid_to_name>:
push   %rbx
mov    %edi,%ebx
call   1040 <getgrgid@plt>
test   %rax,%rax
je     1152 <gid_to_name+0x22>
mov    (%rax),%esi
lea    0x2f0a(%rip),%rdi
mov    $0x40,%edx
call   1030 <strncpy@plt>
jmp    1167 <gid_to_name+0x37>
lea    0x2ef7(%rip),%rdi
lea    0xea0(%rip),%rsi
mov    %ebx,%edx
call   1050 <sprintf@plt>
lea    0x2ee2(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.group = type { i32 }
@gid_to_name.tmp = internal global [64 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @gid_to_name(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.group*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call %struct.group* @getgrgid(i32 %4)
store %struct.group* %5, %struct.group** %3
%6 = load %struct.group*, %struct.group** %3
%7 = icmp ne %struct.group* %6, null
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* %2
%10 = call i32 @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @gid_to_name.tmp, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %16
11: ; preds = %1
%12 = load %struct.group*, %struct.group** %3
%13 = getelementptr inbounds %struct.group, %struct.group* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @strncpy(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @gid_to_name.tmp, i64 0, i64 0), i32 %14, i32 64)
br label %16
16: ; preds = %11, %8
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @gid_to_name.tmp, i64 0, i64 0)
}

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