#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 */
typedef struct data TYPE_1__;

/* Type definitions */
struct data {
  char *name;
  int size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(TYPE_1__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int main() {
  struct data {
    char name[20];
    int size;
  } s[3];
  FILE *stream;
  int i;
  stream = fopen("read.txt", "r");
  fseek(stream, 0, SEEK_END);
  int lSize = ftell(stream);
  rewind(stream);
  fread(s, sizeof(struct data), (int)(lSize / sizeof(struct data)), stream);
  fclose(stream);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xe91(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x58(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
call   1050 <rewind@plt>
lea    -0x50(%rbp),%rdi
movslq -0x60(%rbp),%rax
mov    $0x18,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,%edx
mov    -0x58(%rbp),%rcx
mov    $0x18,%esi
call   1030 <fread@plt>
mov    -0x58(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
lea    0xe93(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <rewind@plt>
movslq %ebp,%rax
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mul    %rcx
shr    $0x4,%rdx
mov    %rsp,%rdi
mov    $0x18,%esi
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.data = type { [20 x i8], i32 }
%struct.data.0 = type { i8*, i32 }
@.str = [9 x i8] c"read.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i32 @main() {
%1 = alloca [3 x %struct.data]
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%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 = load i32, i32* @SEEK_END
%8 = call i32 @fseek(i32* %6, i32 0, i32 %7)
%9 = load i32*, i32** %2
%10 = call i32 @ftell(i32* %9)
store i32 %10, i32* %4
%11 = load i32*, i32** %2
%12 = call i32 @rewind(i32* %11)
%13 = getelementptr inbounds [3 x %struct.data], [3 x %struct.data]* %1, i64 0, i64 0
%14 = bitcast %struct.data* %13 to %struct.data.0*
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = udiv i64 %16, 24
%18 = trunc i64 %17 to i32
%19 = load i32*, i32** %2
%20 = call i32 @fread(%struct.data.0* %14, i32 24, i32 %18, i32* %19)
%21 = load i32*, i32** %2
%22 = call i32 @fclose(i32* %21)
ret i32 0
}

LLVM IR (-O2):
%struct.data = type { [20 x i8], i32 }
%struct.data.0 = type { i8*, i32 }
@.str = [9 x i8] c"read.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i32 @main() {
%1 = alloca [3 x %struct.data]
%2 = getelementptr inbounds [3 x %struct.data], [3 x %struct.data]* %1, i64 0, i64 0, i32 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 = load i32, i32* @SEEK_END
%5 = tail call i32 @fseek(i32* %3, i32 0, i32 %4)
%6 = tail call i32 @ftell(i32* %3)
%7 = tail call i32 @rewind(i32* %3)
%8 = bitcast [3 x %struct.data]* %1 to %struct.data.0*
%9 = sext i32 %6 to i64
%10 = udiv i64 %9, 24
%11 = trunc i64 %10 to i32
%12 = call i32 @fread(%struct.data.0* %8, i32 24, i32 %11, i32* %3)
%13 = tail call i32 @fclose(i32* %3)
ret i32 0
}