#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 */
char *basename(char *);
char *load_banner();
int /*<<< orphan*/ localhost();
int strlen(char *);
scalar_t__ uname(struct utsname *);
int /*<<< orphan*/ write(int, char *, int);
void print_banner(int fd, char *ttyname) {
  char *s, *t, *expansion;
  struct utsname u;
  if (uname(&u))
    u.sysname[0] = u.release[0] = '\0';
  write(fd, "\r\n", 2);
  for (s = load_banner(); *s; s++) {
    for (t = s; *t && *t != '\\'; t++)
      ;
    write(fd, s, t - s);
    if (!*t)
      return;
    switch (*(t + 1)) {
    case '\\':
      expansion = "\\";
      break;
    case 's':
      expansion = u.sysname;
      break;
    case 'r':
      expansion = u.release;
      break;
    case 'n':
      expansion = localhost() ?: "?";
      break;
    case 'l':
      expansion = basename(ttyname);
      break;
    default:
      expansion = "?";
    }
    write(fd, expansion, strlen(expansion));
    s = t + 1;
  }
}


x86 assembly (clang, -O0):
<print_banner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x38(%rbp),%rdi
call   1050 <uname@plt>
cmp    $0x0,%rax
je     1190 <print_banner+0x30>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x4(%rbp),%edi
lea    0xec6(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    $0x0,%al
call   1070 <load_banner@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     132f <print_banner+0x1cf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
je     11e9 <print_banner+0x89>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11f9 <print_banner+0x99>
jmp    120f <print_banner+0xaf>
jmp    11fe <print_banner+0x9e>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11c4 <print_banner+0x64>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    123a <print_banner+0xda>
jmp    132f <print_banner+0x1cf>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
add    $0xffffffa4,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x17,%eax
ja     12e2 <print_banner+0x182>
mov    -0x48(%rbp),%rax
lea    0xda1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xdf4(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    12ed <print_banner+0x18d>
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12ed <print_banner+0x18d>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12ed <print_banner+0x18d>
mov    $0x0,%al
call   1080 <localhost@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
je     12b3 <print_banner+0x153>
mov    -0x4c(%rbp),%eax
cltq
mov    %rax,-0x58(%rbp)
jmp    12c3 <print_banner+0x163>
lea    0xdab(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    12c3 <print_banner+0x163>
mov    -0x58(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    12ed <print_banner+0x18d>
mov    -0x10(%rbp),%rdi
call   1060 <basename@plt>
mov    %rax,-0x28(%rbp)
jmp    12ed <print_banner+0x18d>
lea    0xd7c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11af <print_banner+0x4f>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_banner>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x20(%rsp)
mov    %edi,%r15d
lea    0x8(%rsp),%rdi
call   1050 <uname@plt>
test   %rax,%rax
je     1195 <print_banner+0x35>
mov    0x10(%rsp),%rax
movb   $0x0,(%rax)
mov    0x8(%rsp),%rax
movb   $0x0,(%rax)
lea    0xec4(%rip),%rsi
mov    %r15d,%edi
mov    $0x2,%edx
call   1030 <write@plt>
xor    %eax,%eax
call   1070 <load_banner@plt>
mov    %rax,%rbx
mov    (%rax),%al
test   %al,%al
je     1296 <print_banner+0x136>
mov    0x8(%rsp),%rcx
mov    %rcx,0x18(%rsp)
mov    0x10(%rsp),%r13
lea    0xe90(%rip),%r14
lea    0xe26(%rip),%r12
jmp    120f <print_banner+0xaf>
lea    0xe82(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    (%rbx),%al
test   %al,%al
je     1296 <print_banner+0x136>
mov    %rbx,%rsi
add    $0x2,%rbx
xor    %edx,%edx
test   %al,%al
je     1233 <print_banner+0xd3>
nopl   0x0(%rax)
cmp    $0x5c,%al
je     1233 <print_banner+0xd3>
movzbl -0x1(%rbx),%eax
add    $0x1,%rbx
add    $0x1,%edx
test   %al,%al
jne    1220 <print_banner+0xc0>
mov    %r15d,%edi
call   1030 <write@plt>
cmpb   $0x0,-0x2(%rbx)
je     1296 <print_banner+0x136>
movsbl -0x1(%rbx),%eax
add    $0xffffffa4,%eax
cmp    $0x17,%eax
ja     11dc <print_banner+0x7c>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
mov    %r14,%rbp
jmp    *%rax
mov    0x20(%rsp),%rdi
call   1060 <basename@plt>
mov    %rax,%rbp
jmp    11f0 <print_banner+0x90>
xor    %eax,%eax
call   1080 <localhost@plt>
test   %eax,%eax
movslq %eax,%rbp
lea    0xdea(%rip),%rax
cmove  %rax,%rbp
jmp    11f0 <print_banner+0x90>
mov    %r13,%rbp
jmp    11f0 <print_banner+0x90>
mov    0x18(%rsp),%rbp
jmp    11f0 <print_banner+0x90>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.utsname = type { i8*, i8* }
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [2 x i8] c"\\\00"
@.str.2 = [2 x i8] c"?\00"
define void @print_banner(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca %struct.utsname
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = call i64 @uname(%struct.utsname* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = getelementptr inbounds %struct.utsname, %struct.utsname* %8, i32 0, i32 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 0, i8* %14
%15 = getelementptr inbounds %struct.utsname, %struct.utsname* %8, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 0, i8* %17
br label %18
18: ; preds = %11, %2
%19 = load i32, i32* %3
%20 = call i32 @write(i32 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%21 = call i8* (...) @load_banner()
store i8* %21, i8** %5
br label %22
22: ; preds = %91, %18
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
br i1 %25, label %26, label %94
26: ; preds = %22
%27 = load i8*, i8** %5
store i8* %27, i8** %6
br label %28
28: ; preds = %41, %26
%29 = load i8*, i8** %6
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i8*, i8** %6
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 92
br label %38
38: ; preds = %33, %28
%39 = phi i1 [ false, %28 ], [ %37, %33 ]
br i1 %39, label %40, label %44
40: ; preds = %38
br label %41
41: ; preds = %40
%42 = load i8*, i8** %6
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %6
br label %28
44: ; preds = %38
%45 = load i32, i32* %3
%46 = load i8*, i8** %5
%47 = load i8*, i8** %6
%48 = load i8*, i8** %5
%49 = ptrtoint i8* %47 to i64
%50 = ptrtoint i8* %48 to i64
%51 = sub i64 %49, %50
%52 = trunc i64 %51 to i32
%53 = call i32 @write(i32 %45, i8* %46, i32 %52)
%54 = load i8*, i8** %6
%55 = load i8, i8* %54
%56 = icmp ne i8 %55, 0
br i1 %56, label %58, label %57
57: ; preds = %44
br label %94
58: ; preds = %44
%59 = load i8*, i8** %6
%60 = getelementptr inbounds i8, i8* %59, i64 1
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
switch i32 %62, label %82 [
i32 92, label %63
i32 115, label %64
i32 114, label %67
i32 110, label %70
i32 108, label %79
]
63: ; preds = %58
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %83
64: ; preds = %58
%65 = getelementptr inbounds %struct.utsname, %struct.utsname* %8, i32 0, i32 0
%66 = load i8*, i8** %65
store i8* %66, i8** %7
br label %83
67: ; preds = %58
%68 = getelementptr inbounds %struct.utsname, %struct.utsname* %8, i32 0, i32 1
%69 = load i8*, i8** %68
store i8* %69, i8** %7
br label %83
70: ; preds = %58
%71 = call i32 (...) @localhost()
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %70
%74 = sext i32 %71 to i64
%75 = inttoptr i64 %74 to i8*
br label %77
76: ; preds = %70
br label %77
77: ; preds = %76, %73
%78 = phi i8* [ %75, %73 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %76 ]
store i8* %78, i8** %7
br label %83
79: ; preds = %58
%80 = load i8*, i8** %4
%81 = call i8* @basename(i8* %80)
store i8* %81, i8** %7
br label %83
82: ; preds = %58
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %83
83: ; preds = %82, %79, %77, %67, %64, %63
%84 = load i32, i32* %3
%85 = load i8*, i8** %7
%86 = load i8*, i8** %7
%87 = call i32 @strlen(i8* %86)
%88 = call i32 @write(i32 %84, i8* %85, i32 %87)
%89 = load i8*, i8** %6
%90 = getelementptr inbounds i8, i8* %89, i64 1
store i8* %90, i8** %5
br label %91
91: ; preds = %83
%92 = load i8*, i8** %5
%93 = getelementptr inbounds i8, i8* %92, i32 1
store i8* %93, i8** %5
br label %22
94: ; preds = %57, %22
ret void
}

LLVM IR (-O2):
%struct.utsname = type { i8*, i8* }
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [2 x i8] c"\\\00"
@.str.2 = [2 x i8] c"?\00"
define void @print_banner(i32 %0, i8* %1) {
%3 = alloca %struct.utsname
%4 = bitcast %struct.utsname* %3 to i8*
%5 = call i64 @uname(%struct.utsname* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 1
%9 = load i8*, i8** %8
store i8 0, i8* %9
%10 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%11 = load i8*, i8** %10
store i8 0, i8* %11
br label %12
12: ; preds = %7, %2
%13 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%14 = tail call i8* (...) @load_banner()
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %61, label %17
17: ; preds = %12
%18 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%21 = load i8*, i8** %20
br label %22
22: ; preds = %17, %54
%23 = phi i8 [ %15, %17 ], [ %59, %54 ]
%24 = phi i8* [ %14, %17 ], [ %58, %54 ]
br label %25
25: ; preds = %22, %28
%26 = phi i8 [ %30, %28 ], [ %23, %22 ]
%27 = phi i8* [ %29, %28 ], [ %24, %22 ]
switch i8 %26, label %28 [
i8 0, label %31
i8 92, label %31
]
28: ; preds = %25
%29 = getelementptr inbounds i8, i8* %27, i64 1
%30 = load i8, i8* %29
br label %25
31: ; preds = %25, %25
%32 = ptrtoint i8* %27 to i64
%33 = ptrtoint i8* %24 to i64
%34 = sub i64 %32, %33
%35 = trunc i64 %34 to i32
%36 = tail call i32 @write(i32 %0, i8* %24, i32 %35)
%37 = load i8, i8* %27
%38 = icmp eq i8 %37, 0
br i1 %38, label %61, label %39
39: ; preds = %31
%40 = getelementptr inbounds i8, i8* %27, i64 1
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
switch i32 %42, label %53 [
i32 92, label %54
i32 115, label %43
i32 114, label %44
i32 110, label %45
i32 108, label %51
]
43: ; preds = %39
br label %54
44: ; preds = %39
br label %54
45: ; preds = %39
%46 = tail call i32 (...) @localhost()
%47 = icmp eq i32 %46, 0
%48 = sext i32 %46 to i64
%49 = inttoptr i64 %48 to i8*
%50 = select i1 %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %49
br label %54
51: ; preds = %39
%52 = tail call i8* @basename(i8* %1)
br label %54
53: ; preds = %39
br label %54
54: ; preds = %39, %53, %51, %45, %44, %43
%55 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %53 ], [ %52, %51 ], [ %50, %45 ], [ %19, %44 ], [ %21, %43 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %39 ]
%56 = tail call i32 @strlen(i8* %55)
%57 = tail call i32 @write(i32 %0, i8* %55, i32 %56)
%58 = getelementptr inbounds i8, i8* %27, i64 2
%59 = load i8, i8* %58
%60 = icmp eq i8 %59, 0
br i1 %60, label %61, label %22
61: ; preds = %31, %54, %12
ret void
}