#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 EOF;
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void print_stats(void) {
  FILE *fp_stat;
  int c;
  printf("Stats:\n");
  if ((fp_stat = fopen("/proc/driver/ns_spi/stats", "r")) == NULL) {
    printf("Error opening /proc/driver/ns_spi/stats\n");
    return;
  }
  while ((c = getc(fp_stat)) != EOF)
    putc(c, stdout);
}


x86 assembly (clang, -O0):
<print_stats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
lea    0xead(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1186 <print_stats+0x46>
lea    0xea8(%rip),%rdi
call   1030 <printf@plt>
jmp    11bc <print_stats+0x7c>
jmp    118b <print_stats+0x4b>
mov    -0x8(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%eax
je     11bc <print_stats+0x7c>
mov    -0xc(%rbp),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1040 <putc@plt>
jmp    118b <print_stats+0x4b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_stats>:
push   %r15
push   %r14
push   %rbx
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
lea    0xebf(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11ad <print_stats+0x6d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <getc@plt>
mov    0x2e6d(%rip),%r14
cmp    (%r14),%eax
je     11a7 <print_stats+0x67>
mov    0x2e51(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%r15),%esi
mov    %eax,%edi
call   1040 <putc@plt>
mov    %rbx,%rdi
call   1060 <getc@plt>
cmp    (%r14),%eax
jne    1190 <print_stats+0x50>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe55(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"Stats:\0A\00"
@.str.1 = [26 x i8] c"/proc/driver/ns_spi/stats\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [41 x i8] c"Error opening /proc/driver/ns_spi/stats\0A\00"
@EOF = global i32 0
@stdout = global i32 0
define void @print_stats() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %4, i32** %1
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %18
8: ; preds = %0
br label %9
9: ; preds = %14, %8
%10 = load i32*, i32** %1
%11 = call i32 @getc(i32* %10)
store i32 %11, i32* %2
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* %2
%16 = load i32, i32* @stdout
%17 = call i32 @putc(i32 %15, i32 %16)
br label %9
18: ; preds = %6, %9
ret void
}

LLVM IR (-O2):
@.str.1 = [26 x i8] c"/proc/driver/ns_spi/stats\00"
@.str.2 = [2 x i8] c"r\00"
@EOF = global i32 0
@stdout = global i32 0
@str = [7 x i8] c"Stats:\00"
@str.4 = [40 x i8] c"Error opening /proc/driver/ns_spi/stats\00"
define void @print_stats() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = tail call i32 @getc(i32* %2)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %17, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.4, i64 0, i64 0))
br label %17
10: ; preds = %4, %10
%11 = phi i32 [ %14, %10 ], [ %5, %4 ]
%12 = load i32, i32* @stdout
%13 = tail call i32 @putc(i32 %11, i32 %12)
%14 = tail call i32 @getc(i32* %2)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %10
17: ; preds = %10, %4, %8
ret void
}