#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int read_text_f(FILE *fp, char *array, int nrec, int size) {
  char buf[256];
  register int i;
  int j, n;
  for (i = 0, j = 0; i < nrec; i++) {
    fgets(buf, 256, fp);
    n = strlen(buf);
    strncpy(array + j, buf, size);
    j += size;
  }
  return j;
}


x86 assembly (clang, -O0):
<read_text_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x124(%rbp)
movl   $0x0,-0x128(%rbp)
mov    -0x124(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d3 <read_text_f+0xa3>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x12c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x128(%rbp),%rax
add    %rax,%rdi
lea    -0x120(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%eax
add    -0x128(%rbp),%eax
mov    %eax,-0x128(%rbp)
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    115d <read_text_f+0x2d>
mov    -0x128(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_text_f>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
test   %edx,%edx
jle    1194 <read_text_f+0x64>
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r14
movslq %ecx,%r12
xor    %ebp,%ebp
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
add    %r12,%rbx
add    %r12d,%ebp
add    $0xffffffff,%r15d
jne    1160 <read_text_f+0x30>
jmp    1196 <read_text_f+0x66>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_text_f(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %10
store i32 0, i32* %11
br label %13
13: ; preds = %33, %4
%14 = load i32, i32* %10
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %36
17: ; preds = %13
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%19 = load i32*, i32** %5
%20 = call i32 @fgets(i8* %18, i32 256, i32* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %12
%23 = load i8*, i8** %6
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%28 = load i32, i32* %8
%29 = call i32 @strncpy(i8* %26, i8* %27, i32 %28)
%30 = load i32, i32* %8
%31 = load i32, i32* %11
%32 = add nsw i32 %31, %30
store i32 %32, i32* %11
br label %33
33: ; preds = %17
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
br label %13
36: ; preds = %13
%37 = load i32, i32* %11
ret i32 %37
}

LLVM IR (-O2):
define i32 @read_text_f(i32* nocapture %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = sext i32 %3 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %17, %10 ]
%12 = phi i32 [ 0, %8 ], [ %18, %10 ]
%13 = call i32 @fgets(i8* %6, i32 256, i32* %0)
%14 = call i32 @strlen(i8* %6)
%15 = getelementptr inbounds i8, i8* %1, i64 %11
%16 = call i32 @strncpy(i8* %15, i8* %6, i32 %3)
%17 = add nsw i64 %11, %9
%18 = add nuw nsw i32 %12, 1
%19 = icmp eq i32 %18, %2
br i1 %19, label %20, label %10
20: ; preds = %10
%21 = trunc i64 %17 to i32
br label %22
22: ; preds = %20, %4
%23 = phi i32 [ 0, %4 ], [ %21, %20 ]
ret i32 %23
}