#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*/ al_gen_segment(int, int, int, char *, int *, int *, int);
scalar_t__ al_get_hostname(char *, int);
scalar_t__ al_get_username(char *, int);
scalar_t__ al_is_root_session();
scalar_t__ al_is_ssh_connection();
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int al_segment_host(int *is_first, int *last_bg, int position) {
  char text[64];
  int color_fg = 16;
  int color_bg = 47;
  char username[32];
  char hostname[32];
  if (al_get_username(username, 32) != 0) {
    return -1;
  }
  if (al_get_hostname(hostname, 32) != 0) {
    return -1;
  }
  if (al_is_ssh_connection()) {
    color_fg = 16;
    color_bg = 226;
  } else if (al_is_root_session()) {
    color_fg = 16;
    color_bg = 196;
  }
  snprintf(text, 64, " %s@%s ", username, hostname);
  al_gen_segment(color_fg, color_bg, 1, text, is_first, last_bg, position);
  return 0;
}


x86 assembly (clang, -O0):
<al_segment_host>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x10,-0x64(%rbp)
movl   $0x2f,-0x68(%rbp)
lea    -0x90(%rbp),%rdi
mov    $0x20,%esi
call   1070 <al_get_username@plt>
cmp    $0x0,%rax
je     11ab <al_segment_host+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1266 <al_segment_host+0x106>
lea    -0xb0(%rbp),%rdi
mov    $0x20,%esi
call   1040 <al_get_hostname@plt>
cmp    $0x0,%rax
je     11d2 <al_segment_host+0x72>
movl   $0xffffffff,-0x4(%rbp)
jmp    1266 <al_segment_host+0x106>
mov    $0x0,%al
call   1050 <al_is_ssh_connection@plt>
cmp    $0x0,%rax
je     11f6 <al_segment_host+0x96>
movl   $0x10,-0x64(%rbp)
movl   $0xe2,-0x68(%rbp)
jmp    121a <al_segment_host+0xba>
mov    $0x0,%al
call   1080 <al_is_root_session@plt>
cmp    $0x0,%rax
je     1215 <al_segment_host+0xb5>
movl   $0x10,-0x64(%rbp)
movl   $0xc4,-0x68(%rbp)
jmp    121a <al_segment_host+0xba>
lea    -0x60(%rbp),%rdi
lea    -0x90(%rbp),%rcx
lea    -0xb0(%rbp),%r8
mov    $0x40,%esi
lea    0xdc8(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x64(%rbp),%edi
mov    -0x68(%rbp),%esi
lea    -0x60(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    -0x1c(%rbp),%eax
mov    $0x1,%edx
mov    %eax,(%rsp)
call   1060 <al_gen_segment@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<al_segment_host>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x30(%rsp),%rdi
mov    $0x20,%esi
call   1070 <al_get_username@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1218 <al_segment_host+0xb8>
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
call   1040 <al_get_hostname@plt>
test   %rax,%rax
jne    1218 <al_segment_host+0xb8>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <al_is_ssh_connection@plt>
mov    $0xe2,%r12d
test   %rax,%rax
jne    11d7 <al_segment_host+0x77>
xor    %eax,%eax
call   1080 <al_is_root_session@plt>
test   %rax,%rax
mov    $0x2f,%eax
mov    $0xc4,%r12d
cmove  %eax,%r12d
lea    0xe22(%rip),%rdx
lea    0x50(%rsp),%r13
lea    0x30(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %r13,%rdi
mov    $0x40,%esi
call   1030 <snprintf@plt>
mov    %ebx,(%rsp)
mov    $0x10,%edi
mov    %r12d,%esi
mov    $0x1,%edx
mov    %r13,%rcx
mov    %r15,%r8
mov    %r14,%r9
call   1060 <al_gen_segment@plt>
mov    %ebp,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c" %s@%s \00"
define i32 @al_segment_host(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [64 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca [32 x i8]
%12 = alloca [32 x i8]
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 16, i32* %9
store i32 47, i32* %10
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%14 = call i64 @al_get_username(i8* %13, i32 32)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %43
17: ; preds = %3
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%19 = call i64 @al_get_hostname(i8* %18, i32 32)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %4
br label %43
22: ; preds = %17
%23 = call i64 (...) @al_is_ssh_connection()
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 16, i32* %9
store i32 226, i32* %10
br label %31
26: ; preds = %22
%27 = call i64 (...) @al_is_root_session()
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 16, i32* %9
store i32 196, i32* %10
br label %30
30: ; preds = %29, %26
br label %31
31: ; preds = %30, %25
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%35 = call i32 @snprintf(i8* %32, i32 64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %34)
%36 = load i32, i32* %9
%37 = load i32, i32* %10
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%39 = load i32*, i32** %5
%40 = load i32*, i32** %6
%41 = load i32, i32* %7
%42 = call i32 @al_gen_segment(i32 %36, i32 %37, i32 1, i8* %38, i32* %39, i32* %40, i32 %41)
store i32 0, i32* %4
br label %43
43: ; preds = %31, %21, %16
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@.str = [8 x i8] c" %s@%s \00"
define i32 @al_segment_host(i32* %0, i32* %1, i32 %2) {
%4 = alloca [64 x i8]
%5 = alloca [32 x i8]
%6 = alloca [32 x i8]
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%10 = call i64 @al_get_username(i8* %8, i32 32)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %3
%13 = call i64 @al_get_hostname(i8* %9, i32 32)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = call i64 (...) @al_is_ssh_connection()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = call i64 (...) @al_is_root_session()
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i32 47, i32 196
br label %22
22: ; preds = %18, %15
%23 = phi i32 [ 226, %15 ], [ %21, %18 ]
%24 = call i32 @snprintf(i8* %7, i32 64, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %9)
%25 = call i32 @al_gen_segment(i32 16, i32 %23, i32 1, i8* %7, i32* %0, i32* %1, i32 %2)
br label %26
26: ; preds = %12, %3, %22
%27 = phi i32 [ 0, %22 ], [ -1, %3 ], [ -1, %12 ]
ret i32 %27
}