#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 */
struct utsname {
  char *sysname;
  char *release;
};

/* Variables and functions */
int asprintf(char **, char *, char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ basename(char *);
char *localhost();
scalar_t__ uname(struct utsname *);
int /*<<< orphan*/ write(int, char *, int);
void print_banner(int fd, char *ttyname) {
  int cc;
  char *s;
  struct utsname u;
  char *hostname = localhost();
  if (uname(&u))
    u.sysname[0] = u.release[0] = '\0';
  cc = asprintf(&s, "\r\n\n%s %s (%s) (%s)\r\n\n", u.sysname, u.release,
                hostname ?: "?", basename(ttyname));
  write(fd, s, cc);
}


x86 assembly (clang, -O0):
<print_banner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <localhost@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <uname@plt>
cmp    $0x0,%rax
je     118b <print_banner+0x3b>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     11ba <print_banner+0x6a>
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    11ca <print_banner+0x7a>
lea    0xe55(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    11ca <print_banner+0x7a>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <basename@plt>
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x60(%rbp),%r8
mov    %eax,%r9d
lea    -0x20(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1060 <asprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_banner>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
xor    %eax,%eax
call   1070 <localhost@plt>
mov    %rax,%rbp
mov    %rsp,%rdi
call   1040 <uname@plt>
test   %rax,%rax
je     1190 <print_banner+0x40>
mov    0x8(%rsp),%r12
movb   $0x0,(%r12)
mov    (%rsp),%r13
movb   $0x0,0x0(%r13)
jmp    1199 <print_banner+0x49>
mov    (%rsp),%r13
mov    0x8(%rsp),%r12
test   %rbp,%rbp
lea    0xe73(%rip),%rbx
cmovne %rbp,%rbx
mov    %r15,%rdi
call   1050 <basename@plt>
lea    0xe4a(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
mov    %eax,%r9d
call   1060 <asprintf@plt>
mov    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.utsname = type { i8*, i8* }
@.str = [22 x i8] c"\0D\0A\0A%s %s (%s) (%s)\0D\0A\0A\00"
@.str.1 = [2 x i8] c"?\00"
define void @print_banner(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.utsname
%8 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = call i8* (...) @localhost()
store i8* %9, i8** %8
%10 = call i64 @uname(%struct.utsname* %7)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = getelementptr inbounds %struct.utsname, %struct.utsname* %7, i32 0, i32 1
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 0, i8* %15
%16 = getelementptr inbounds %struct.utsname, %struct.utsname* %7, i32 0, i32 0
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 0, i8* %18
br label %19
19: ; preds = %12, %2
%20 = getelementptr inbounds %struct.utsname, %struct.utsname* %7, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = getelementptr inbounds %struct.utsname, %struct.utsname* %7, i32 0, i32 1
%23 = load i8*, i8** %22
%24 = load i8*, i8** %8
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %19
br label %28
27: ; preds = %19
br label %28
28: ; preds = %27, %26
%29 = phi i8* [ %24, %26 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %27 ]
%30 = load i8*, i8** %4
%31 = call i32 @basename(i8* %30)
%32 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23, i8* %29, i32 %31)
store i32 %32, i32* %5
%33 = load i32, i32* %3
%34 = load i8*, i8** %6
%35 = load i32, i32* %5
%36 = call i32 @write(i32 %33, i8* %34, i32 %35)
ret void
}

LLVM IR (-O2):
%struct.utsname = type { i8*, i8* }
@.str = [22 x i8] c"\0D\0A\0A%s %s (%s) (%s)\0D\0A\0A\00"
@.str.1 = [2 x i8] c"?\00"
define void @print_banner(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca %struct.utsname
%5 = bitcast i8** %3 to i8*
%6 = bitcast %struct.utsname* %4 to i8*
%7 = tail call i8* (...) @localhost()
%8 = call i64 @uname(%struct.utsname* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i64 0, i32 1
%14 = load i8*, i8** %13
br label %20
15: ; preds = %2
%16 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i64 0, i32 1
%17 = load i8*, i8** %16
store i8 0, i8* %17
%18 = getelementptr inbounds %struct.utsname, %struct.utsname* %4, i64 0, i32 0
%19 = load i8*, i8** %18
store i8 0, i8* %19
br label %20
20: ; preds = %10, %15
%21 = phi i8* [ %14, %10 ], [ %17, %15 ]
%22 = phi i8* [ %12, %10 ], [ %19, %15 ]
%23 = icmp eq i8* %7, null
%24 = select i1 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %7
%25 = tail call i32 @basename(i8* %1)
%26 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %21, i8* %24, i32 %25)
%27 = load i8*, i8** %3
%28 = call i32 @write(i32 %0, i8* %27, i32 %26)
ret void
}