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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getgid();
struct group *getgrgid(int /*<<< orphan*/);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int /*<<< orphan*/ printf(char *, char *, char *);
char *strerror(int /*<<< orphan*/);
void errExitErrnoUGID(char *msg) {
  struct passwd *user;
  struct group *grp;
  printf("%s: %s\n", msg, strerror(errno));
  user = getpwuid(getuid());
  grp = getgrgid(getgid());
  printf("Access from user: %s, group: %s\n",
         (user == NULL) ? NULL : user->pw_name,
         (grp == NULL) ? NULL : grp->gr_name);
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<errExitErrnoUGID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <getgid@plt>
mov    %eax,%edi
call   1060 <getgrgid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11df <errExitErrnoUGID+0x6f>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    11ea <errExitErrnoUGID+0x7a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1208 <errExitErrnoUGID+0x98>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    1213 <errExitErrnoUGID+0xa3>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xde6(%rip),%rdi
call   1050 <printf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<errExitErrnoUGID>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe74(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1050 <printf@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <getuid@plt>
mov    %eax,%edi
call   1030 <getpwuid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <getgid@plt>
mov    %eax,%edi
call   1060 <getgrgid@plt>
test   %rbx,%rbx
je     11c1 <errExitErrnoUGID+0x51>
mov    (%rbx),%r14
test   %rax,%rax
jne    11ca <errExitErrnoUGID+0x5a>
xor    %edx,%edx
jmp    11cd <errExitErrnoUGID+0x5d>
mov    (%rax),%rdx
lea    0xe34(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i8* }
%struct.group = type { i8* }
@.str = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
@.str.1 = [33 x i8] c"Access from user: %s, group: %s\0A\00"
@EXIT_FAILURE = global i32 0
define void @errExitErrnoUGID(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.passwd*
%4 = alloca %struct.group*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @errno
%7 = call i8* @strerror(i32 %6)
%8 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %7)
%9 = call i32 (...) @getuid()
%10 = call %struct.passwd* @getpwuid(i32 %9)
store %struct.passwd* %10, %struct.passwd** %3
%11 = call i32 (...) @getgid()
%12 = call %struct.group* @getgrgid(i32 %11)
store %struct.group* %12, %struct.group** %4
%13 = load %struct.passwd*, %struct.passwd** %3
%14 = icmp eq %struct.passwd* %13, null
br i1 %14, label %15, label %16
15: ; preds = %1
br label %20
16: ; preds = %1
%17 = load %struct.passwd*, %struct.passwd** %3
%18 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i32 0, i32 0
%19 = load i8*, i8** %18
br label %20
20: ; preds = %16, %15
%21 = phi i8* [ null, %15 ], [ %19, %16 ]
%22 = load %struct.group*, %struct.group** %4
%23 = icmp eq %struct.group* %22, null
br i1 %23, label %24, label %25
24: ; preds = %20
br label %29
25: ; preds = %20
%26 = load %struct.group*, %struct.group** %4
%27 = getelementptr inbounds %struct.group, %struct.group* %26, i32 0, i32 0
%28 = load i8*, i8** %27
br label %29
29: ; preds = %25, %24
%30 = phi i8* [ null, %24 ], [ %28, %25 ]
%31 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
%struct.group = type { i8* }
@.str = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
@.str.1 = [33 x i8] c"Access from user: %s, group: %s\0A\00"
@EXIT_FAILURE = global i32 0
define void @errExitErrnoUGID(i8* %0) {
%2 = load i32, i32* @errno
%3 = tail call i8* @strerror(i32 %2)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %3)
%5 = tail call i32 (...) @getuid()
%6 = tail call %struct.passwd* @getpwuid(i32 %5)
%7 = tail call i32 (...) @getgid()
%8 = tail call %struct.group* @getgrgid(i32 %7)
%9 = icmp eq %struct.passwd* %6, null
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i64 0, i32 0
%12 = load i8*, i8** %11
br label %13
13: ; preds = %1, %10
%14 = phi i8* [ %12, %10 ], [ null, %1 ]
%15 = icmp eq %struct.group* %8, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = getelementptr inbounds %struct.group, %struct.group* %8, i64 0, i32 0
%18 = load i8*, i8** %17
br label %19
19: ; preds = %13, %16
%20 = phi i8* [ %18, %16 ], [ null, %13 ]
%21 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %14, i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
}