#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*/ *fopen(char *, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int _print_motd() {
  FILE *fp;
  size_t nbytes = 80;
  char read[nbytes];
  size_t result;
  if ((fp = fopen("/etc/motd", "r")) == NULL) {
    return (-1);
  }
  while ((result = fread(read, sizeof(char), nbytes, fp))) {
    result = fwrite(read, sizeof(char), result, stdout);
  }
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<_print_motd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x50,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe82(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11ab <_print_motd+0x6b>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    120f <_print_motd+0xcf>
jmp    11b0 <_print_motd+0x70>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11f8 <_print_motd+0xb8>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    0x2dfd(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    %rax,-0x30(%rbp)
jmp    11b0 <_print_motd+0x70>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_print_motd>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
lea    0xeb0(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c9 <_print_motd+0x89>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x50,%edx
mov    $0x1,%esi
mov    %rax,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11bd <_print_motd+0x7d>
mov    0x2e5b(%rip),%r15
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1060 <fwrite@plt>
mov    $0x50,%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    1190 <_print_motd+0x50>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11ce <_print_motd+0x8e>
mov    $0xffffffff,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/etc/motd\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @_print_motd() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i64 80, i64* %3
%8 = load i64, i64* %3
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %4
%10 = alloca i8, i64 %8
store i64 %8, i64* %5
%11 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %0
store i32 -1, i32* %1
store i32 1, i32* %7
br label %27
14: ; preds = %0
br label %15
15: ; preds = %20, %14
%16 = load i64, i64* %3
%17 = load i32*, i32** %2
%18 = call i64 @fread(i8* %10, i32 1, i64 %16, i32* %17)
store i64 %18, i64* %6
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i64, i64* %6
%22 = load i32, i32* @stdout
%23 = call i64 @fwrite(i8* %10, i32 1, i64 %21, i32 %22)
store i64 %23, i64* %6
br label %15
24: ; preds = %15
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
store i32 0, i32* %1
store i32 1, i32* %7
br label %27
27: ; preds = %24, %13
%28 = load i8*, i8** %4
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [10 x i8] c"/etc/motd\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @_print_motd() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %16, label %5
5: ; preds = %0
%6 = call i64 @fread(i8* %2, i32 1, i64 80, i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5, %8
%9 = phi i64 [ %12, %8 ], [ %6, %5 ]
%10 = load i32, i32* @stdout
%11 = call i64 @fwrite(i8* %2, i32 1, i64 %9, i32 %10)
%12 = call i64 @fread(i8* %2, i32 1, i64 80, i32* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %8
14: ; preds = %8, %5
%15 = call i32 @fclose(i32* %3)
br label %16
16: ; preds = %0, %14
%17 = phi i32 [ 0, %14 ], [ -1, %0 ]
ret i32 %17
}