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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119c <main+0x4c>
lea    0xe80(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <main+0x8f>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3c,%esi
call   1040 <fgets@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
lea    0xea4(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a5 <main+0x55>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x3c,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbx
ret
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
jmp    119f <main+0x4f>

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

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