#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
void print_issue(char *tty_dev) {
  FILE *f;
  char s[1120];
  f = fopen("/etc/issue", "r");
  if (!f) {
    perror("getty; could not open issue file:");
    return;
  }
  while (fgets(s, 1120, f) != NULL) {
    if (!strcmp(s, "<ttydev>\n"))
      printf("%s\n", tty_dev);
    else
      printf("%s", s);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<print_issue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a2 <print_issue+0x42>
lea    0xe75(%rip),%rdi
call   1080 <perror@plt>
jmp    1218 <print_issue+0xb8>
jmp    11a7 <print_issue+0x47>
lea    -0x470(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x460,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     120f <print_issue+0xaf>
lea    -0x470(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11f7 <print_issue+0x97>
mov    -0x8(%rbp),%rsi
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
jmp    120a <print_issue+0xaa>
lea    -0x470(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
jmp    11a7 <print_issue+0x47>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_issue>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x468,%rsp
mov    %rdi,%r14
lea    0xe95(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1217 <print_issue+0xc7>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x460,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fd <print_issue+0xad>
movabs $0x3e7665647974743c,%rbp
65 76 3e
lea    0xe90(%rip),%r15
mov    %rsp,%r12
lea    0xe8a(%rip),%r13
jmp    11e0 <print_issue+0x90>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    $0x460,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fd <print_issue+0xad>
mov    (%rsp),%rax
xor    %rbp,%rax
movzwl 0x8(%rsp),%ecx
xor    $0xa,%rcx
or     %rax,%rcx
jne    11c0 <print_issue+0x70>
mov    %r15,%rdi
mov    %r14,%rsi
jmp    11c6 <print_issue+0x76>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x468,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdef(%rip),%rdi
add    $0x468,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <perror@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/etc/issue\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"getty; could not open issue file:\00"
@.str.3 = [10 x i8] c"<ttydev>\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define void @print_issue(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [1120 x i8]
store i8* %0, i8** %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %30
10: ; preds = %1
br label %11
11: ; preds = %26, %10
%12 = getelementptr inbounds [1120 x i8], [1120 x i8]* %4, i64 0, i64 0
%13 = load i32*, i32** %3
%14 = call i32* @fgets(i8* %12, i32 1120, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %27
16: ; preds = %11
%17 = getelementptr inbounds [1120 x i8], [1120 x i8]* %4, i64 0, i64 0
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %21)
br label %26
23: ; preds = %16
%24 = getelementptr inbounds [1120 x i8], [1120 x i8]* %4, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %20
br label %11
27: ; preds = %11
%28 = load i32*, i32** %3
%29 = call i32 @fclose(i32* %28)
br label %30
30: ; preds = %27, %8
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/etc/issue\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"getty; could not open issue file:\00"
@.str.3 = [10 x i8] c"<ttydev>\0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [3 x i8] c"%s\00"
define void @print_issue(i8* %0) {
%2 = alloca [1120 x i8]
%3 = getelementptr inbounds [1120 x i8], [1120 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = call i32* @fgets(i8* %3, i32 1120, i32* %4)
%8 = icmp eq i32* %7, null
br i1 %8, label %21, label %11
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %23
11: ; preds = %6, %18
%12 = call i32 @bcmp(i8* dereferenceable(10) %3, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i64 10)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %18
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %3)
br label %18
18: ; preds = %16, %14
%19 = call i32* @fgets(i8* %3, i32 1120, i32* %4)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %11
21: ; preds = %18, %6
%22 = call i32 @fclose(i32* %4)
br label %23
23: ; preds = %21, %9
ret void
}