#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 /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *ft_cmd_env_get(char *);
int ft_get_next_line(int /*<<< orphan*/, char **);
int /*<<< orphan*/ ft_putstr(char *);
int /*<<< orphan*/ ft_sh_perror(char *);
char *ft_sh_prompt(void) {
  char *cmd;
  int res;
  if (ft_cmd_env_get("USER"))
    ft_putstr(ft_cmd_env_get("USER"));
  else
    ft_putstr("42sh-v1.0");
  ft_putstr(" $> ");
  res = ft_get_next_line(0, &cmd);
  if (res == -1) {
    ft_sh_perror("42sh: ");
    exit(EXIT_FAILURE);
  } else if (res == 0)
    exit(EXIT_SUCCESS);
  return (cmd);
}


x86 assembly (clang, -O0):
<ft_sh_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1040 <ft_cmd_env_get@plt>
cmp    $0x0,%rax
je     1187 <ft_sh_prompt+0x37>
lea    0xe8b(%rip),%rdi
call   1040 <ft_cmd_env_get@plt>
mov    %rax,%rdi
call   1060 <ft_putstr@plt>
jmp    1193 <ft_sh_prompt+0x43>
lea    0xe77(%rip),%rdi
call   1060 <ft_putstr@plt>
lea    0xe75(%rip),%rdi
call   1060 <ft_putstr@plt>
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   1030 <ft_get_next_line@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11d1 <ft_sh_prompt+0x81>
lea    0xe56(%rip),%rdi
call   1050 <ft_sh_perror@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11e9 <ft_sh_prompt+0x99>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11ee <ft_sh_prompt+0x9e>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_sh_prompt>:
push   %rax
lea    0xea8(%rip),%rdi
call   1040 <ft_cmd_env_get@plt>
test   %rax,%rax
je     1173 <ft_sh_prompt+0x23>
lea    0xe97(%rip),%rdi
call   1040 <ft_cmd_env_get@plt>
mov    %rax,%rdi
jmp    117a <ft_sh_prompt+0x2a>
lea    0xe8b(%rip),%rdi
call   1060 <ft_putstr@plt>
lea    0xe89(%rip),%rdi
call   1060 <ft_putstr@plt>
mov    %rsp,%rsi
xor    %edi,%edi
call   1030 <ft_get_next_line@plt>
test   %eax,%eax
je     11a4 <ft_sh_prompt+0x54>
cmp    $0xffffffff,%eax
je     11b2 <ft_sh_prompt+0x62>
mov    (%rsp),%rax
pop    %rcx
ret
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe5b(%rip),%rdi
call   1050 <ft_sh_perror@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"USER\00"
@.str.1 = [10 x i8] c"42sh-v1.0\00"
@.str.2 = [5 x i8] c" $> \00"
@.str.3 = [7 x i8] c"42sh: \00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i8* @ft_sh_prompt() {
%1 = alloca i8*
%2 = alloca i32
%3 = call i8* @ft_cmd_env_get(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp ne i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i8* @ft_cmd_env_get(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @ft_putstr(i8* %6)
br label %10
8: ; preds = %0
%9 = call i32 @ft_putstr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = call i32 @ft_putstr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @ft_get_next_line(i32 0, i8** %1)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = call i32 @ft_sh_perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* @EXIT_SUCCESS
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %19
br label %26
26: ; preds = %25
%27 = load i8*, i8** %1
ret i8* %27
}

LLVM IR (-O2):
@.str = [5 x i8] c"USER\00"
@.str.1 = [10 x i8] c"42sh-v1.0\00"
@.str.2 = [5 x i8] c" $> \00"
@.str.3 = [7 x i8] c"42sh: \00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i8* @ft_sh_prompt() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i8* @ft_cmd_env_get(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i8* @ft_cmd_env_get(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %0, %5
%8 = phi i8* [ %6, %5 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %0 ]
%9 = tail call i32 @ft_putstr(i8* %8)
%10 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @ft_get_next_line(i32 0, i8** %1)
switch i32 %11, label %19 [
i32 -1, label %12
i32 0, label %16
]
12: ; preds = %7
%13 = call i32 @ft_sh_perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %7
%17 = load i32, i32* @EXIT_SUCCESS
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %7
%20 = load i8*, i8** %1
ret i8* %20
}