#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 */
char *getlogin();
scalar_t__ malloc(unsigned char);
int /*<<< orphan*/ snprintf(char *, unsigned char, char *, char *, char *);
int strlen(char *);
char *get_prompt() {
  char *login;
  char *prompt;
  unsigned char prompt_total_bytes;
  login = getlogin();
  prompt_total_bytes =
      (sizeof(char) * 13) + (sizeof(char) * (strlen(login) + 2));
  prompt = (char *)malloc(prompt_total_bytes);
  snprintf(prompt, prompt_total_bytes, "[%s%s]$", login, "@NutShell");
  return prompt;
}


x86 assembly (clang, -O0):
<get_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <getlogin@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x2,%eax
cltq
shl    $0x0,%rax
add    $0xd,%rax
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x11(%rbp),%al
mov    -0x8(%rbp),%rcx
lea    0xe75(%rip),%rdx
lea    0xe76(%rip),%r8
movzbl %al,%esi
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_prompt>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1060 <getlogin@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
add    $0xf,%al
movzbl %al,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe94(%rip),%rdx
lea    0xe95(%rip),%r8
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"[%s%s]$\00"
@.str.1 = [10 x i8] c"@NutShell\00"
define i8* @get_prompt() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8
%4 = call i8* (...) @getlogin()
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = call i32 @strlen(i8* %5)
%7 = add nsw i32 %6, 2
%8 = sext i32 %7 to i64
%9 = mul i64 1, %8
%10 = add i64 13, %9
%11 = trunc i64 %10 to i8
store i8 %11, i8* %3
%12 = load i8, i8* %3
%13 = call i64 @malloc(i8 zeroext %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %2
%15 = load i8*, i8** %2
%16 = load i8, i8* %3
%17 = load i8*, i8** %1
%18 = call i32 @snprintf(i8* %15, i8 zeroext %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = load i8*, i8** %2
ret i8* %19
}

LLVM IR (-O2):
@.str = [8 x i8] c"[%s%s]$\00"
@.str.1 = [10 x i8] c"@NutShell\00"
define i8* @get_prompt() {
%1 = tail call i8* (...) @getlogin()
%2 = tail call i32 @strlen(i8* %1)
%3 = trunc i32 %2 to i8
%4 = add i8 %3, 15
%5 = tail call i64 @malloc(i8 zeroext %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @snprintf(i8* %6, i8 zeroext %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
ret i8* %6
}