#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 */
scalar_t__ fvec_fwrite(int /*<<< orphan*/ *, float const *, int);
int fvecs_fwrite(FILE *fo, int d, int n, const float *vf) {
  int i;
  for (i = 0; i < n; i++) {
    if (fvec_fwrite(fo, vf + i * d, d) < 0) {
      return i;
    }
  }
  return n;
}


x86 assembly (clang, -O0):
<fvecs_fwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1181 <fvecs_fwrite+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1030 <fvec_fwrite@plt>
cmp    $0x0,%rax
jge    116e <fvecs_fwrite+0x5e>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <fvecs_fwrite+0x77>
jmp    1173 <fvecs_fwrite+0x63>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112d <fvecs_fwrite+0x1d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fvecs_fwrite>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
test   %edx,%edx
jle    1164 <fvecs_fwrite+0x54>
mov    %rcx,%rbx
mov    %esi,%r12d
mov    %rdi,%r15
movslq %esi,%r13
shl    $0x2,%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <fvec_fwrite@plt>
test   %rax,%rax
js     1161 <fvecs_fwrite+0x51>
add    $0x1,%rbp
add    %r13,%rbx
cmp    %rbp,%r14
jne    1140 <fvecs_fwrite+0x30>
jmp    1164 <fvecs_fwrite+0x54>
mov    %ebp,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @fvecs_fwrite(i32* %0, i32 %1, i32 %2, float* %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %20
6: ; preds = %4
%7 = sext i32 %1 to i64
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %6, %15
%10 = phi i64 [ 0, %6 ], [ %16, %15 ]
%11 = mul nsw i64 %10, %7
%12 = getelementptr inbounds float, float* %3, i64 %11
%13 = tail call i64 @fvec_fwrite(i32* %0, float* %12, i32 %1)
%14 = icmp slt i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = add nuw nsw i64 %10, 1
%17 = icmp eq i64 %16, %8
br i1 %17, label %20, label %9
18: ; preds = %9
%19 = trunc i64 %10 to i32
br label %20
20: ; preds = %15, %18, %4
%21 = phi i32 [ %2, %4 ], [ %19, %18 ], [ %2, %15 ]
ret i32 %21
}