#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*/ snprintf(char *, int, char *, int, ...);
char *gid_rep(gid_t gid) {
  static char buf[200];
  struct group *gr = getgrgid(gid);
  if (gr)
    snprintf(buf, sizeof buf, "%d(%s)", gid, gr->gr_name);
  else
    snprintf(buf, sizeof buf, "%d", gid);
  return buf;
}


x86 assembly (clang, -O0):
<gid_rep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <getgrgid@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116b <gid_rep+0x4b>
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    (%rax),%r8
lea    0x2eed(%rip),%rdi
mov    $0xc8,%esi
lea    0xea1(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    1188 <gid_rep+0x68>
mov    -0x4(%rbp),%ecx
lea    0x2ecb(%rip),%rdi
mov    $0xc8,%esi
lea    0xe86(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    0x2eb1(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gid_rep>:
push   %rbx
mov    %edi,%ebx
call   1030 <getgrgid@plt>
test   %rax,%rax
je     114e <gid_rep+0x2e>
mov    (%rax),%r8
lea    0x2f09(%rip),%rdi
lea    0xec2(%rip),%rdx
mov    $0xc8,%esi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    116a <gid_rep+0x4a>
lea    0x2eeb(%rip),%rdi
lea    0xeab(%rip),%rdx
mov    $0xc8,%esi
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0x2ecf(%rip),%rax
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.group = type { i8* }
@gid_rep.buf = internal global [200 x i8] zeroinitializer
@.str = [7 x i8] c"%d(%s)\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @gid_rep(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 i8*, i8** %5
%7 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @gid_rep.buf, i64 0, i64 0), i32 200, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %6)
br label %10
8: ; preds = %1
%9 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([200 x i8], [200 x i8]* @gid_rep.buf, i64 0, i64 0), i32 200, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %10
10: ; preds = %8, %4
ret i8* getelementptr inbounds ([200 x i8], [200 x i8]* @gid_rep.buf, i64 0, i64 0)
}