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

/* Variables and functions */
struct group *getgrgid(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
extern char *gid_to_name(gid_t gid) {
  struct group *grp = getgrgid(gid);
  static char str[10];
  if (grp == NULL) {
    sprintf(str, "%d", gid);
    return str;
  } else {
    return grp->gr_name;
  }
}


x86 assembly (clang, -O0):
<gid_to_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1168 <gid_to_name+0x48>
mov    -0xc(%rbp),%edx
lea    0x2ee5(%rip),%rdi
lea    0xead(%rip),%rsi
call   1040 <sprintf@plt>
lea    0x2ed2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1173 <gid_to_name+0x53>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gid_to_name>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1030 <getgrgid@plt>
test   %rax,%rax
je     1134 <gid_to_name+0x14>
mov    (%rax),%rbx
jmp    114c <gid_to_name+0x2c>
lea    0x2ef6(%rip),%rbx
lea    0xebe(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.group = type { i8* }
@gid_to_name.str = internal global [10 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 ([10 x i8], [10 x i8]* @gid_to_name.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %9
6: ; preds = %1
%7 = getelementptr inbounds %struct.group, %struct.group* %2, i64 0, i32 0
%8 = load i8*, i8** %7
br label %9
9: ; preds = %6, %4
%10 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @gid_to_name.str, i64 0, i64 0), %4 ], [ %8, %6 ]
ret i8* %10
}