#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 {
  int /*<<< orphan*/ pw_name;
};
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ gethostname(char *, int);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
void *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
char **getuserhost() {
  char **data;
  if ((data = malloc(2 * sizeof(char *))) == NULL) {
    exit(EXIT_FAILURE);
  }
  data[0] = malloc(50 * sizeof(char));
  data[1] = malloc(50 * sizeof(char));
  struct passwd *p = getpwuid(getuid());
  if (p != NULL) {
    strncpy(data[0], p->pw_name, 49);
  } else {
    strcpy(data[0], "unknown");
  }
  if (gethostname(data[1], sizeof(data[1])) == 0) {
    return data;
  } else {
    strcpy(data[1], "unknown");
    return data;
  }
}


x86 assembly (clang, -O0):
<getuserhost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    119e <getuserhost+0x2e>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    $0x0,%al
call   1060 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1200 <getuserhost+0x90>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    $0x31,%edx
call   1030 <strncpy@plt>
jmp    1213 <getuserhost+0xa3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdf2(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x8,%esi
call   1080 <gethostname@plt>
cmp    $0x0,%rax
jne    123c <getuserhost+0xcc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1258 <getuserhost+0xe8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdb5(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getuserhost>:
push   %r15
push   %r14
push   %rbx
mov    $0x10,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1209 <getuserhost+0x99>
mov    %rax,%r15
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%r15)
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x8(%r15)
xor    %eax,%eax
call   1060 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
test   %rax,%rax
je     11d0 <getuserhost+0x60>
mov    (%rax),%esi
mov    %rbx,%rdi
mov    $0x31,%edx
call   1030 <strncpy@plt>
jmp    11df <getuserhost+0x6f>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    $0x8,%esi
call   1080 <gethostname@plt>
test   %rax,%rax
je     1200 <getuserhost+0x90>
lea    0xe08(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
%struct.passwd = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [8 x i8] c"unknown\00"
define noalias i8** @getuserhost() {
%1 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%2 = bitcast i8* %1 to i8**
%3 = icmp eq i8* %1, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %0
%8 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
store i8* %8, i8** %2
%9 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%10 = getelementptr inbounds i8*, i8** %2, i64 1
store i8* %9, i8** %10
%11 = tail call i32 (...) @getuid()
%12 = tail call %struct.passwd* @getpwuid(i32 %11)
%13 = icmp eq %struct.passwd* %12, null
br i1 %13, label %18, label %14
14: ; preds = %7
%15 = getelementptr inbounds %struct.passwd, %struct.passwd* %12, i64 0, i32 0
%16 = load i32, i32* %15
%17 = tail call i32 @strncpy(i8* %8, i32 %16, i32 49)
br label %20
18: ; preds = %7
%19 = tail call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = tail call i64 @gethostname(i8* %9, i32 8)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %20, %23
ret i8** %2
}