#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
void write_allbank(char *p_file, float *banks, int ntrials, int nbets) {
  FILE *fp;
  int ii, jj;
  if ((fp = fopen(p_file, "w")) == NULL) {
    printf("Couldn't open file: %s\n", p_file);
    exit(1);
  }
  for (ii = 0; ii < ntrials; ii++) {
    for (jj = 0; jj < nbets; jj++) {
      fprintf(fp, "%f\t", banks[nbets * ii + jj]);
    }
    fprintf(fp, "\n");
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<write_allbank>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    119e <write_allbank+0x4e>
mov    -0x8(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121e <write_allbank+0xce>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11fe <write_allbank+0xae>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0x24(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe31(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b8 <write_allbank+0x68>
mov    -0x20(%rbp),%rdi
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a5 <write_allbank+0x55>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_allbank>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0x4(%rsp)
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1228 <write_allbank+0xc8>
mov    %rax,%rbp
test   %r15d,%r15d
jle    1212 <write_allbank+0xb2>
movslq 0x4(%rsp),%rax
mov    %r15d,%ecx
mov    %rcx,0x8(%rsp)
mov    %eax,%r14d
shl    $0x2,%rax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
lea    0xe5f(%rip),%r15
jmp    11dd <write_allbank+0x7d>
nopl   (%rax)
mov    $0xa,%edi
mov    %rbp,%rsi
call   1050 <fputc@plt>
add    $0x1,%r13
add    0x10(%rsp),%rbx
cmp    0x8(%rsp),%r13
je     1212 <write_allbank+0xb2>
cmpl   $0x0,0x4(%rsp)
jle    11c0 <write_allbank+0x60>
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movss  (%rbx,%r12,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    11f0 <write_allbank+0x90>
jmp    11c0 <write_allbank+0x60>
mov    %rbp,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xdd3(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [24 x i8] c"Couldn't open file: %s\0A\00"
@.str.2 = [4 x i8] c"%f\09\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @write_allbank(i8* %0, float* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca float*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store float* %1, float** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %9
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %4
%16 = load i8*, i8** %5
%17 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %4
store i32 0, i32* %10
br label %20
20: ; preds = %48, %19
%21 = load i32, i32* %10
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %51
24: ; preds = %20
store i32 0, i32* %11
br label %25
25: ; preds = %42, %24
%26 = load i32, i32* %11
%27 = load i32, i32* %8
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %45
29: ; preds = %25
%30 = load i32*, i32** %9
%31 = load float*, float** %6
%32 = load i32, i32* %8
%33 = load i32, i32* %10
%34 = mul nsw i32 %32, %33
%35 = load i32, i32* %11
%36 = add nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds float, float* %31, i64 %37
%39 = load float, float* %38
%40 = fpext float %39 to double
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %40)
br label %42
42: ; preds = %29
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %25
45: ; preds = %25
%46 = load i32*, i32** %9
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %45
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %20
51: ; preds = %20
%52 = load i32*, i32** %9
%53 = call i32 @fclose(i32* %52)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [24 x i8] c"Couldn't open file: %s\0A\00"
@.str.2 = [4 x i8] c"%f\09\00"
define void @write_allbank(i8* %0, float* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %34
9: ; preds = %7
%10 = icmp sgt i32 %3, 0
%11 = sext i32 %3 to i64
%12 = zext i32 %2 to i64
%13 = zext i32 %3 to i64
br label %17
14: ; preds = %4
%15 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9, %30
%18 = phi i64 [ 0, %9 ], [ %32, %30 ]
br i1 %10, label %19, label %30
19: ; preds = %17
%20 = mul nsw i64 %18, %11
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 0, %19 ], [ %28, %21 ]
%23 = add nsw i64 %22, %20
%24 = getelementptr inbounds float, float* %1, i64 %23
%25 = load float, float* %24
%26 = fpext float %25 to double
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %26)
%28 = add nuw nsw i64 %22, 1
%29 = icmp eq i64 %28, %13
br i1 %29, label %30, label %21
30: ; preds = %21, %17
%31 = tail call i32 @fputc(i32 10, i32* %5)
%32 = add nuw nsw i64 %18, 1
%33 = icmp eq i64 %32, %12
br i1 %33, label %34, label %17
34: ; preds = %30, %7
%35 = tail call i32 @fclose(i32* %5)
ret void
}