#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*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int main(void) {
  FILE *fp = fopen("/tmp/vmirtest", "rb");
  if (fp == NULL)
    abort();
  char buf[10];
  int r = fread(buf, 1, 10, fp);
  buf[r] = 0;
  puts(buf);
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1181 <main+0x31>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x12(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0xa,%edx
call   1050 <fread@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x0,-0x12(%rbp,%rax,1)
lea    -0x12(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xea2(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ad <main+0x5d>
mov    %rax,%rbx
lea    0xe(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xa,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
cltq
movb   $0x0,0xe(%rsp,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/tmp/vmirtest\00"
@.str.1 = [3 x i8] c"rb\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (...) @abort()
unreachable
9: ; preds = %0
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%11 = load i32*, i32** %1
%12 = call i32 @fread(i8* %10, i32 1, i32 10, i32* %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %14
store i8 0, i8* %15
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%17 = call i32 @puts(i8* %16)
%18 = load i32*, i32** %1
%19 = call i32 @fclose(i32* %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/tmp/vmirtest\00"
@.str.1 = [3 x i8] c"rb\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 (...) @abort()
unreachable
6: ; preds = %0
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%8 = call i32 @fread(i8* %7, i32 1, i32 10, i32* %2)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i32 @puts(i8* %7)
%12 = tail call i32 @fclose(i32* %2)
ret i32 0
}