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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
struct group *getgrgid(int /*<<< orphan*/);
char *strdup(int /*<<< orphan*/);
int myls_get_groupname(struct stat *filename_stat, char **str) {
  struct group *grp;
  grp = getgrgid(filename_stat->st_gid);
  if (grp == NULL)
    return EXIT_FAILURE;
  *str = strdup(grp->gr_name);
  if (*str == NULL)
    return EXIT_FAILURE;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<myls_get_groupname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <getgrgid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115b <myls_get_groupname+0x3b>
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    119b <myls_get_groupname+0x7b>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1040 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    118f <myls_get_groupname+0x6f>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    119b <myls_get_groupname+0x7b>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myls_get_groupname>:
push   %rbx
mov    %rsi,%rbx
mov    (%rdi),%edi
call   1030 <getgrgid@plt>
test   %rax,%rax
je     113f <myls_get_groupname+0x1f>
mov    (%rax),%edi
call   1040 <strdup@plt>
mov    %rax,(%rbx)
test   %rax,%rax
jne    1148 <myls_get_groupname+0x28>
mov    0x2e9a(%rip),%rax
jmp    114f <myls_get_groupname+0x2f>
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.group = type { i32 }
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @myls_get_groupname(%struct.stat* %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.stat*
%5 = alloca i8**
%6 = alloca %struct.group*
store %struct.stat* %0, %struct.stat** %4
store i8** %1, i8*** %5
%7 = load %struct.stat*, %struct.stat** %4
%8 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call %struct.group* @getgrgid(i32 %9)
store %struct.group* %10, %struct.group** %6
%11 = load %struct.group*, %struct.group** %6
%12 = icmp eq %struct.group* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %28
15: ; preds = %2
%16 = load %struct.group*, %struct.group** %6
%17 = getelementptr inbounds %struct.group, %struct.group* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i8* @strdup(i32 %18)
%20 = load i8**, i8*** %5
store i8* %19, i8** %20
%21 = load i8**, i8*** %5
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = load i32, i32* @EXIT_FAILURE
store i32 %25, i32* %3
br label %28
26: ; preds = %15
%27 = load i32, i32* @EXIT_SUCCESS
store i32 %27, i32* %3
br label %28
28: ; preds = %26, %24, %13
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.group = type { i32 }
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @myls_get_groupname(%struct.stat* nocapture %0, i8** nocapture writeonly %1) {
%3 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = tail call %struct.group* @getgrgid(i32 %4)
%6 = icmp eq %struct.group* %5, null
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = getelementptr inbounds %struct.group, %struct.group* %5, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i8* @strdup(i32 %9)
store i8* %10, i8** %1
%11 = icmp eq i8* %10, null
%12 = select i1 %11, i32* @EXIT_FAILURE, i32* @EXIT_SUCCESS
br label %13
13: ; preds = %7, %2
%14 = phi i32* [ @EXIT_FAILURE, %2 ], [ %12, %7 ]
%15 = load i32, i32* %14
ret i32 %15
}