#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 HOST_NAME_MAX;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gethostname(char *, int);
char *getlogin();
char *malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *, char *);
size_t strlen(char *);
char *user_at_host_str() {
  char *userstr, *hoststr, *res;
  size_t userstrlen, hoststrlen, reslen, ressize;
  userstr = getlogin();
  hoststr = malloc(sizeof(char) * HOST_NAME_MAX);
  memset(hoststr, 0, sizeof(char) * HOST_NAME_MAX);
  gethostname(hoststr, HOST_NAME_MAX);
  userstrlen = strlen(userstr);
  hoststrlen = strlen(hoststr);
  reslen = userstrlen + 1 + hoststrlen + 1;
  ressize = sizeof(char) * reslen;
  res = malloc(ressize);
  snprintf(res, ressize, "%s@%s", userstr, hoststr);
  free(hoststr);
  return res;
}


x86 assembly (clang, -O0):
<user_at_host_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x0,%al
call   1080 <getlogin@plt>
mov    %rax,-0x8(%rbp)
mov    0x2e5e(%rip),%rax
movslq (%rax),%rdi
shl    $0x0,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e43(%rip),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1090 <gethostname@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
add    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
shl    $0x0,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xddb(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<user_at_host_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <getlogin@plt>
mov    %rax,%r14
mov    0x2e5f(%rip),%r12
mov    (%r12),%eax
movslq %eax,%r15
mov    %r15,%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1090 <gethostname@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %rax,%r15
add    $0x2,%r15
mov    %r15,%rdi
call   1070 <malloc@plt>
mov    %rax,%r12
lea    0xe20(%rip),%rdx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
mov    %rbx,%r8
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@HOST_NAME_MAX = global i32 0
@.str = [6 x i8] c"%s@%s\00"
define i8* @user_at_host_str() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = call i8* (...) @getlogin()
store i8* %8, i8** %1
%9 = load i32, i32* @HOST_NAME_MAX
%10 = sext i32 %9 to i64
%11 = mul i64 1, %10
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %2
%13 = load i8*, i8** %2
%14 = load i32, i32* @HOST_NAME_MAX
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i32 @memset(i8* %13, i32 0, i32 %17)
%19 = load i8*, i8** %2
%20 = load i32, i32* @HOST_NAME_MAX
%21 = call i32 @gethostname(i8* %19, i32 %20)
%22 = load i8*, i8** %1
%23 = call i64 @strlen(i8* %22)
store i64 %23, i64* %4
%24 = load i8*, i8** %2
%25 = call i64 @strlen(i8* %24)
store i64 %25, i64* %5
%26 = load i64, i64* %4
%27 = add i64 %26, 1
%28 = load i64, i64* %5
%29 = add i64 %27, %28
%30 = add i64 %29, 1
store i64 %30, i64* %6
%31 = load i64, i64* %6
%32 = mul i64 1, %31
store i64 %32, i64* %7
%33 = load i64, i64* %7
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %3
%35 = load i8*, i8** %3
%36 = load i64, i64* %7
%37 = load i8*, i8** %1
%38 = load i8*, i8** %2
%39 = call i32 @snprintf(i8* %35, i64 %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %37, i8* %38)
%40 = load i8*, i8** %2
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %3
ret i8* %42
}

LLVM IR (-O2):
@HOST_NAME_MAX = global i32 0
@.str = [6 x i8] c"%s@%s\00"
define i8* @user_at_host_str() {
%1 = tail call i8* (...) @getlogin()
%2 = load i32, i32* @HOST_NAME_MAX
%3 = sext i32 %2 to i64
%4 = tail call i8* @malloc(i64 %3)
%5 = tail call i32 @memset(i8* %4, i32 0, i32 %2)
%6 = load i32, i32* @HOST_NAME_MAX
%7 = tail call i32 @gethostname(i8* %4, i32 %6)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%10 = add i64 %8, 2
%11 = add i64 %10, %9
%12 = tail call i8* @malloc(i64 %11)
%13 = tail call i32 @snprintf(i8* %12, i64 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %4)
%14 = tail call i32 @free(i8* %4)
ret i8* %12
}