#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 */
char EOF;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
void print_file(char *file_path) {
  FILE *file;
  file = fopen(file_path, "r");
  if (file == NULL) {
    printf("Error opening file %s\n", file_path);
  } else {
    printf("%s\n", file_path);
    int counter = 0;
    char c;
    while (counter < 30) {
      c = fgetc(file);
      if (c == EOF) {
        break;
      }
      printf("%c", c);
      counter++;
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<print_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1172 <print_file+0x42>
mov    -0x8(%rbp),%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ea <print_file+0xba>
mov    -0x8(%rbp),%rsi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x1e,-0x14(%rbp)
jge    11dc <print_file+0xac>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
mov    0x2e3c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11bc <print_file+0x8c>
jmp    11dc <print_file+0xac>
movsbl -0x15(%rbp),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <print_file+0x5b>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11a8 <print_file+0x58>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <puts@plt>
mov    $0x1e,%ebp
mov    0x2e69(%rip),%r14
nop
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%al
je     119a <print_file+0x4a>
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1180 <print_file+0x30>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>
lea    0xe53(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"Error opening file %s\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@EOF = global i8 0
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @print_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %36
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %14)
store i32 0, i32* %4
br label %16
16: ; preds = %28, %13
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 30
br i1 %18, label %19, label %34
19: ; preds = %16
%20 = load i32*, i32** %3
%21 = call signext i8 @fgetc(i32* %20)
store i8 %21, i8* %5
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = load i8, i8* @EOF
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %23, %25
br i1 %26, label %27, label %28
27: ; preds = %19
br label %34
28: ; preds = %19
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %16
34: ; preds = %27, %16
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %10
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"Error opening file %s\0A\00"
@EOF = global i8 0
define void @print_file(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %20
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) %0)
br label %8
8: ; preds = %6, %13
%9 = phi i32 [ 0, %6 ], [ %16, %13 ]
%10 = tail call signext i8 @fgetc(i32* %2)
%11 = load i8, i8* @EOF
%12 = icmp eq i8 %10, %11
br i1 %12, label %18, label %13
13: ; preds = %8
%14 = sext i8 %10 to i32
%15 = tail call i32 @putchar(i32 %14)
%16 = add nuw nsw i32 %9, 1
%17 = icmp eq i32 %16, 30
br i1 %17, label %18, label %8
18: ; preds = %8, %13
%19 = tail call i32 @putchar(i32 10)
br label %20
20: ; preds = %18, %4
ret void
}