#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 stat {
  int /*<<< orphan*/ st_gid;
  int /*<<< orphan*/ st_uid;
};
struct passwd {
  char *pw_name;
};
struct group {
  char *gr_name;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct group *getgrgid(int /*<<< orphan*/);
struct passwd *getpwuid(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
char *make_user_group_string(struct stat *s) {
  struct passwd *pw = getpwuid(s->st_uid);
  if (pw == NULL)
    exit(EXIT_FAILURE);
  struct group *gr = getgrgid(s->st_gid);
  if (gr == NULL)
    exit(EXIT_FAILURE);
  int size = strlen(pw->pw_name) + strlen(gr->gr_name) + 2;
  char *result = (char *)malloc(size);
  sprintf(result, "%s %s", pw->pw_name, gr->gr_name);
  return result;
}


x86 assembly (clang, -O0):
<make_user_group_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1195 <make_user_group_string+0x35>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bd <make_user_group_string+0x5d>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xdf6(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_user_group_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
je     11d2 <make_user_group_string+0x72>
mov    %rax,%r14
mov    (%rbx),%edi
call   1050 <getgrgid@plt>
test   %rax,%rax
je     11d2 <make_user_group_string+0x72>
mov    %rax,%r12
mov    (%r14),%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    (%r12),%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    (%r14),%rdx
mov    (%r12),%rcx
lea    0xe45(%rip),%rsi
mov    %rax,%rdi
call   1070 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
%struct.passwd = type { i8* }
%struct.group = type { i8* }
@EXIT_FAILURE = global i32 0
@.str = [6 x i8] c"%s %s\00"
define i8* @make_user_group_string(%struct.stat* %0) {
%2 = alloca %struct.stat*
%3 = alloca %struct.passwd*
%4 = alloca %struct.group*
%5 = alloca i32
%6 = alloca i8*
store %struct.stat* %0, %struct.stat** %2
%7 = load %struct.stat*, %struct.stat** %2
%8 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%9 = load i32, i32* %8
%10 = call %struct.passwd* @getpwuid(i32 %9)
store %struct.passwd* %10, %struct.passwd** %3
%11 = load %struct.passwd*, %struct.passwd** %3
%12 = icmp eq %struct.passwd* %11, null
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
%17 = load %struct.stat*, %struct.stat** %2
%18 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call %struct.group* @getgrgid(i32 %19)
store %struct.group* %20, %struct.group** %4
%21 = load %struct.group*, %struct.group** %4
%22 = icmp eq %struct.group* %21, null
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %16
%27 = load %struct.passwd*, %struct.passwd** %3
%28 = getelementptr inbounds %struct.passwd, %struct.passwd* %27, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = call i32 @strlen(i8* %29)
%31 = load %struct.group*, %struct.group** %4
%32 = getelementptr inbounds %struct.group, %struct.group* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %30, %34
%36 = add nsw i32 %35, 2
store i32 %36, i32* %5
%37 = load i32, i32* %5
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %6
%40 = load i8*, i8** %6
%41 = load %struct.passwd*, %struct.passwd** %3
%42 = getelementptr inbounds %struct.passwd, %struct.passwd* %41, i32 0, i32 0
%43 = load i8*, i8** %42
%44 = load %struct.group*, %struct.group** %4
%45 = getelementptr inbounds %struct.group, %struct.group* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %43, i8* %46)
%48 = load i8*, i8** %6
ret i8* %48
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
%struct.passwd = type { i8* }
%struct.group = type { i8* }
@EXIT_FAILURE = global i32 0
@.str = [6 x i8] c"%s %s\00"
define i8* @make_user_group_string(%struct.stat* nocapture %0) {
%2 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 1
%3 = load i32, i32* %2
%4 = tail call %struct.passwd* @getpwuid(i32 %3)
%5 = icmp eq %struct.passwd* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call %struct.group* @getgrgid(i32 %11)
%13 = icmp eq %struct.group* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %9
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %4, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = tail call i32 @strlen(i8* %19)
%21 = getelementptr inbounds %struct.group, %struct.group* %12, i64 0, i32 0
%22 = load i8*, i8** %21
%23 = tail call i32 @strlen(i8* %22)
%24 = add i32 %20, 2
%25 = add i32 %24, %23
%26 = tail call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
%28 = load i8*, i8** %18
%29 = load i8*, i8** %21
%30 = tail call i32 @sprintf(i8* dereferenceable(1) %27, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29)
ret i8* %27
}