#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 scalar_t__ uid_t;
struct passwd {
  char *pw_name;
};
struct group {
  char *gr_name;
};
typedef scalar_t__ gid_t;

/* Variables and functions */
struct group *getgrgid(scalar_t__);
struct passwd *getpwuid(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, long, long);
const char *uid_gid_string(uid_t uid, gid_t gid) {
  static char buf[255];
  struct passwd *p = 0;
  struct group *g = 0;
  p = getpwuid(uid);
  g = getgrgid(gid);
  sprintf(buf, "%.100s/%.100s (%ld/%ld)",
          (p && p->pw_name ? p->pw_name : "???"),
          (g && g->gr_name ? g->gr_name : "???"), (long)uid, (long)gid);
  return buf;
}


x86 assembly (clang, -O0):
<uid_gid_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getgrgid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1193 <uid_gid_string+0x63>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     1193 <uid_gid_string+0x63>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11a3 <uid_gid_string+0x73>
lea    0xe7e(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11a3 <uid_gid_string+0x73>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d4 <uid_gid_string+0xa4>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     11d4 <uid_gid_string+0xa4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    11e4 <uid_gid_string+0xb4>
lea    0xe3d(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    11e4 <uid_gid_string+0xb4>
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    -0x10(%rbp),%r9
lea    0x2e55(%rip),%rdi
lea    0xdfe(%rip),%rsi
call   1050 <sprintf@plt>
lea    0x2e42(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uid_gid_string>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <getpwuid@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <getgrgid@plt>
lea    0xec6(%rip),%rcx
mov    %rcx,%rdx
test   %rbx,%rbx
je     116b <uid_gid_string+0x3b>
mov    (%rbx),%rsi
test   %rsi,%rsi
lea    0xeb1(%rip),%rdx
cmovne %rsi,%rdx
test   %rax,%rax
je     1181 <uid_gid_string+0x51>
mov    (%rax),%rax
test   %rax,%rax
lea    0xe9b(%rip),%rcx
cmovne %rax,%rcx
lea    0x2ec8(%rip),%rbx
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%r8
mov    %r14,%r9
call   1050 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
%struct.group = type { i8* }
@uid_gid_string.buf = internal global [255 x i8] zeroinitializer
@.str = [24 x i8] c"%.100s/%.100s (%ld/%ld)\00"
@.str.1 = [4 x i8] c"???\00"
define i8* @uid_gid_string(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca %struct.passwd*
%6 = alloca %struct.group*
store i64 %0, i64* %3
store i64 %1, i64* %4
store %struct.passwd* null, %struct.passwd** %5
store %struct.group* null, %struct.group** %6
%7 = load i64, i64* %3
%8 = call %struct.passwd* @getpwuid(i64 %7)
store %struct.passwd* %8, %struct.passwd** %5
%9 = load i64, i64* %4
%10 = call %struct.group* @getgrgid(i64 %9)
store %struct.group* %10, %struct.group** %6
%11 = load %struct.passwd*, %struct.passwd** %5
%12 = icmp ne %struct.passwd* %11, null
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load %struct.passwd*, %struct.passwd** %5
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load %struct.passwd*, %struct.passwd** %5
%20 = getelementptr inbounds %struct.passwd, %struct.passwd* %19, i32 0, i32 0
%21 = load i8*, i8** %20
br label %23
22: ; preds = %13, %2
br label %23
23: ; preds = %22, %18
%24 = phi i8* [ %21, %18 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %22 ]
%25 = load %struct.group*, %struct.group** %6
%26 = icmp ne %struct.group* %25, null
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = load %struct.group*, %struct.group** %6
%29 = getelementptr inbounds %struct.group, %struct.group* %28, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load %struct.group*, %struct.group** %6
%34 = getelementptr inbounds %struct.group, %struct.group* %33, i32 0, i32 0
%35 = load i8*, i8** %34
br label %37
36: ; preds = %27, %23
br label %37
37: ; preds = %36, %32
%38 = phi i8* [ %35, %32 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %36 ]
%39 = load i64, i64* %3
%40 = load i64, i64* %4
%41 = call i32 @sprintf(i8* getelementptr inbounds ([255 x i8], [255 x i8]* @uid_gid_string.buf, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %38, i64 %39, i64 %40)
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @uid_gid_string.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
%struct.group = type { i8* }
@uid_gid_string.buf = internal global [255 x i8] zeroinitializer
@.str = [24 x i8] c"%.100s/%.100s (%ld/%ld)\00"
@.str.1 = [4 x i8] c"???\00"
define i8* @uid_gid_string(i64 %0, i64 %1) {
%3 = tail call %struct.passwd* @getpwuid(i64 %0)
%4 = tail call %struct.group* @getgrgid(i64 %1)
%5 = icmp eq %struct.passwd* %3, null
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = getelementptr inbounds %struct.passwd, %struct.passwd* %3, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
%10 = select i1 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %8
br label %11
11: ; preds = %6, %2
%12 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %2 ], [ %10, %6 ]
%13 = icmp eq %struct.group* %4, null
br i1 %13, label %19, label %14
14: ; preds = %11
%15 = getelementptr inbounds %struct.group, %struct.group* %4, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
%18 = select i1 %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %16
br label %19
19: ; preds = %14, %11
%20 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %11 ], [ %18, %14 ]
%21 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([255 x i8], [255 x i8]* @uid_gid_string.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %20, i64 %0, i64 %1)
ret i8* getelementptr inbounds ([255 x i8], [255 x i8]* @uid_gid_string.buf, i64 0, i64 0)
}