#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*/ *fopen(char const *, char const *);
size_t fread(void *, size_t, size_t, int /*<<< orphan*/ *);
void *malloc(int);
int main() {
  const char *path = "a.1";
  const char *mode = "r";
  FILE *stream = fopen(path, mode);
  if (!stream) {
    return 1;
  }
  void *ptr = malloc(10);
  size_t size = 1;
  size_t nmemb = 2;
  size_t sret = fread(ptr, size, nmemb, stream);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117d <main+0x4d>
movl   $0x1,-0x4(%rbp)
jmp    11bb <main+0x8b>
mov    $0xa,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
movq   $0x2,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <fread@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
lea    0xec5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     116f <main+0x3f>
mov    %rax,%rbx
mov    $0xa,%edi
call   1040 <malloc@plt>
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rax,%rdi
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"a.1\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%5 = tail call i64 @fread(i8* %4, i64 1, i64 2, i32* %1)
br label %6
6: ; preds = %0, %3
%7 = phi i32 [ 0, %3 ], [ 1, %0 ]
ret i32 %7
}