#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int _POSIX_HOST_NAME_MAX;
scalar_t__ _POSIX_LOGIN_NAME_MAX;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *get_hostname();
char *get_username();
char *malloc(scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *get_prompt(void) {
  char *prompt;
  char *username = get_username();
  char *hostname = get_hostname();
  prompt = malloc(_POSIX_LOGIN_NAME_MAX + _POSIX_HOST_NAME_MAX + 1);
  if (!prompt) {
    fprintf(stderr, "Error: Failedto allocate memory\n");
    exit(EXIT_FAILURE);
  }
  strncpy(prompt, username, _POSIX_LOGIN_NAME_MAX + 1);
  strncat(prompt, "@", 2);
  strncat(prompt, hostname, _POSIX_HOST_NAME_MAX + 1);
  free(username);
  free(hostname);
  return prompt;
}


x86 assembly (clang, -O0):
<get_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <get_username@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1090 <get_hostname@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%rdi
mov    0x2e11(%rip),%rax
movslq (%rax),%rax
add    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11f0 <get_prompt+0x70>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2de9(%rip),%rax
mov    (%rax),%rdx
add    $0x1,%rdx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xe0b(%rip),%rsi
mov    $0x2,%edx
call   1060 <strncat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
add    $0x1,%edx
call   1060 <strncat@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_prompt>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
xor    %eax,%eax
call   1050 <get_username@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1090 <get_hostname@plt>
mov    %rax,%r15
mov    0x2e44(%rip),%rax
mov    (%rax),%rbx
mov    0x2e12(%rip),%r13
movslq 0x0(%r13),%rax
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     121c <get_prompt+0x9c>
mov    %rax,%r12
add    $0x1,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <strncpy@plt>
lea    0xe41(%rip),%rsi
mov    %r12,%rdi
mov    $0x2,%edx
call   1060 <strncat@plt>
mov    0x0(%r13),%edx
add    $0x1,%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <strncat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xdd4(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@_POSIX_LOGIN_NAME_MAX = global i64 0
@_POSIX_HOST_NAME_MAX = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"Error: Failedto allocate memory\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"@\00"
define i8* @get_prompt() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* (...) @get_username()
store i8* %4, i8** %2
%5 = call i8* (...) @get_hostname()
store i8* %5, i8** %3
%6 = load i64, i64* @_POSIX_LOGIN_NAME_MAX
%7 = load i32, i32* @_POSIX_HOST_NAME_MAX
%8 = sext i32 %7 to i64
%9 = add nsw i64 %6, %8
%10 = add nsw i64 %9, 1
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %1
%12 = load i8*, i8** %1
%13 = icmp ne i8* %12, null
br i1 %13, label %19, label %14
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %0
%20 = load i8*, i8** %1
%21 = load i8*, i8** %2
%22 = load i64, i64* @_POSIX_LOGIN_NAME_MAX
%23 = add nsw i64 %22, 1
%24 = call i32 @strncpy(i8* %20, i8* %21, i64 %23)
%25 = load i8*, i8** %1
%26 = call i32 @strncat(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
%27 = load i8*, i8** %1
%28 = load i8*, i8** %3
%29 = load i32, i32* @_POSIX_HOST_NAME_MAX
%30 = add nsw i32 %29, 1
%31 = call i32 @strncat(i8* %27, i8* %28, i32 %30)
%32 = load i8*, i8** %2
%33 = call i32 @free(i8* %32)
%34 = load i8*, i8** %3
%35 = call i32 @free(i8* %34)
%36 = load i8*, i8** %1
ret i8* %36
}

LLVM IR (-O2):
@_POSIX_LOGIN_NAME_MAX = global i64 0
@_POSIX_HOST_NAME_MAX = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"Error: Failedto allocate memory\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"@\00"
define i8* @get_prompt() {
%1 = tail call i8* (...) @get_username()
%2 = tail call i8* (...) @get_hostname()
%3 = load i64, i64* @_POSIX_LOGIN_NAME_MAX
%4 = load i32, i32* @_POSIX_HOST_NAME_MAX
%5 = sext i32 %4 to i64
%6 = add i64 %3, 1
%7 = add i64 %6, %5
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = tail call i32 @strncpy(i8* %8, i8* %1, i64 %6)
%17 = tail call i32 @strncat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
%18 = load i32, i32* @_POSIX_HOST_NAME_MAX
%19 = add nsw i32 %18, 1
%20 = tail call i32 @strncat(i8* %8, i8* %2, i32 %19)
%21 = tail call i32 @free(i8* %1)
%22 = tail call i32 @free(i8* %2)
ret i8* %8
}