#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*/ puts(char *);
int main() {
  FILE *fp;
  char str[60];
  fp = fopen("file.txt", "r");
  if (fp == NULL) {
    perror("Error opening file");
    return (-1);
  }
  if (fgets(str, 60, fp) != NULL) {
    puts(str);
  }
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <main+0x49>
lea    0xe83(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <main+0x7e>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3c,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11be <main+0x6e>
lea    -0x50(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
lea    0xea4(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119d <main+0x4d>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x3c,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     118d <main+0x3d>
mov    %rsp,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret
lea    0xe67(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
jmp    1197 <main+0x47>

LLVM IR (-O0):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Error opening file\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [60 x i8]
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %20
9: ; preds = %0
%10 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i32* @fgets(i8* %10, i32 60, i32* %11)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%16 = call i32 @puts(i8* %15)
br label %17
17: ; preds = %14, %9
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
store i32 0, i32* %1
br label %20
20: ; preds = %17, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Error opening file\00"
define i32 @main() {
%1 = alloca [60 x i8]
%2 = getelementptr inbounds [60 x i8], [60 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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 %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %14
7: ; preds = %0
%8 = call i32* @fgets(i8* %2, i32 60, i32* %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @puts(i8* %2)
br label %12
12: ; preds = %10, %7
%13 = call i32 @fclose(i32* %3)
br label %14
14: ; preds = %12, %5
%15 = phi i32 [ -1, %5 ], [ 0, %12 ]
ret i32 %15
}