#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 /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *, char *);
void create_codebook_text_file(char filename[], float lsp[], int rows,
                               int cols) {
  FILE *f;
  int i, digits[10];
  f = fopen(filename, "wt");
  if (f == NULL) {
    printf("Can't open codebook text file %s\n", filename);
    exit(0);
  }
  for (i = 0; i < rows; i++)
    digits[i] = 0;
  fprintf(f, "%d %d\n", rows, (int)pow(cols, rows));
  do {
    for (i = 0; i < rows; i++)
      fprintf(f, "%4.0f ", lsp[cols * i + digits[i]]);
    fprintf(f, "\n");
    digits[0]++;
    for (i = 0; i < rows - 1; i++)
      if (digits[i] == cols) {
        digits[i] = 0;
        digits[i + 1]++;
      }
  } while (digits[rows - 1] != cols);
  fclose(f);
}


x86 assembly (clang, -O0):
<create_codebook_text_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ac <create_codebook_text_file+0x4c>
mov    -0x8(%rbp),%rsi
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d9 <create_codebook_text_file+0x79>
movslq -0x24(%rbp),%rax
movl   $0x0,-0x50(%rbp,%rax,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b3 <create_codebook_text_file+0x53>
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1070 <pow@plt>
mov    -0x60(%rbp),%rdi
mov    -0x54(%rbp),%edx
mov    %eax,%ecx
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125b <create_codebook_text_file+0xfb>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0x24(%rbp),%ecx
movslq -0x24(%rbp),%rdx
add    -0x50(%rbp,%rdx,4),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde6(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1210 <create_codebook_text_file+0xb0>
mov    -0x20(%rbp),%rdi
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12d1 <create_codebook_text_file+0x171>
movslq -0x24(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%eax
cmp    -0x18(%rbp),%eax
jne    12be <create_codebook_text_file+0x15e>
movslq -0x24(%rbp),%rax
movl   $0x0,-0x50(%rbp,%rax,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x50(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x50(%rbp,%rax,4)
jmp    12c3 <create_codebook_text_file+0x163>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127d <create_codebook_text_file+0x11d>
jmp    12d6 <create_codebook_text_file+0x176>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x50(%rbp,%rax,4),%eax
cmp    -0x18(%rbp),%eax
jne    1209 <create_codebook_text_file+0xa9>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_codebook_text_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe60(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12fa <create_codebook_text_file+0x17a>
mov    %rax,%r13
mov    %r14,0x28(%rsp)
mov    %r15d,%ebp
test   %r15d,%r15d
jle    11d2 <create_codebook_text_file+0x52>
lea    0x0(,%rbp,4),%rdx
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rbp,0x18(%rsp)
mov    %ebx,%edi
mov    %r15d,%esi
call   1090 <pow@plt>
lea    0xe3d(%rip),%rsi
mov    %r13,%rdi
mov    %r15d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    -0x1(%r15),%edx
movslq %edx,%rax
mov    %rax,0x8(%rsp)
movslq %ebx,%r12
mov    %ebx,0x4(%rsp)
mov    %r15,0x20(%rsp)
mov    %rdx,0x10(%rsp)
mov    0x18(%rsp),%rbp
jmp    122f <create_codebook_text_file+0xaf>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
cmp    %ebx,0x30(%rsp,%rax,4)
je     12e4 <create_codebook_text_file+0x164>
test   %r15d,%r15d
mov    0x28(%rsp),%rbx
mov    %r13,%r14
jle    127e <create_codebook_text_file+0xfe>
xor    %r15d,%r15d
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq 0x30(%rsp,%r13,4),%rax
add    %r15,%rax
movss  (%rbx,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
lea    0xdc1(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
add    $0x1,%r13
add    %r12,%r15
cmp    %r13,%rbp
jne    1250 <create_codebook_text_file+0xd0>
mov    $0xa,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    0x30(%rsp),%ecx
add    $0x1,%ecx
mov    %ecx,0x30(%rsp)
mov    0x20(%rsp),%r15
cmp    $0x2,%r15d
mov    0x4(%rsp),%ebx
mov    %r14,%r13
mov    0x10(%rsp),%rdx
jl     1220 <create_codebook_text_file+0xa0>
xor    %eax,%eax
cmp    %ebx,%ecx
jne    12cd <create_codebook_text_file+0x14d>
nopw   0x0(%rax,%rax,1)
movl   $0x0,0x30(%rsp,%rax,4)
addl   $0x1,0x34(%rsp,%rax,4)
add    $0x1,%rax
cmp    %rdx,%rax
je     1220 <create_codebook_text_file+0xa0>
mov    0x30(%rsp,%rax,4),%ecx
cmp    %ebx,%ecx
je     12c0 <create_codebook_text_file+0x140>
jmp    12cd <create_codebook_text_file+0x14d>
mov    %r13,%rdi
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xd02(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wt\00"
@.str.1 = [34 x i8] c"Can't open codebook text file %s\0A\00"
@.str.2 = [7 x i8] c"%d %d\0A\00"
@.str.3 = [7 x i8] c"%4.0f \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @create_codebook_text_file(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 [10 x 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 ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %9
%14 = load i32*, i32** %9
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i8*, i8** %5
%18 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %4
store i32 0, i32* %10
br label %21
21: ; preds = %29, %20
%22 = load i32, i32* %10
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %27
store i32 0, i32* %28
br label %29
29: ; preds = %25
%30 = load i32, i32* %10
%31 = add nsw i32 %30, 1
store i32 %31, i32* %10
br label %21
32: ; preds = %21
%33 = load i32*, i32** %9
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = call i64 @pow(i32 %35, i32 %36)
%38 = trunc i64 %37 to i32
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %38)
br label %40
40: ; preds = %97, %32
store i32 0, i32* %10
br label %41
41: ; preds = %61, %40
%42 = load i32, i32* %10
%43 = load i32, i32* %7
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %64
45: ; preds = %41
%46 = load i32*, i32** %9
%47 = load float*, float** %6
%48 = load i32, i32* %8
%49 = load i32, i32* %10
%50 = mul nsw i32 %48, %49
%51 = load i32, i32* %10
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = add nsw i32 %50, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds float, float* %47, i64 %56
%58 = load float, float* %57
%59 = fpext float %58 to double
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %59)
br label %61
61: ; preds = %45
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
br label %41
64: ; preds = %41
%65 = load i32*, i32** %9
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%67 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 0
%68 = load i32, i32* %67
%69 = add nsw i32 %68, 1
store i32 %69, i32* %67
store i32 0, i32* %10
br label %70
70: ; preds = %93, %64
%71 = load i32, i32* %10
%72 = load i32, i32* %7
%73 = sub nsw i32 %72, 1
%74 = icmp slt i32 %71, %73
br i1 %74, label %75, label %96
75: ; preds = %70
%76 = load i32, i32* %10
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %77
%79 = load i32, i32* %78
%80 = load i32, i32* %8
%81 = icmp eq i32 %79, %80
br i1 %81, label %82, label %92
82: ; preds = %75
%83 = load i32, i32* %10
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %84
store i32 0, i32* %85
%86 = load i32, i32* %10
%87 = add nsw i32 %86, 1
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %88
%90 = load i32, i32* %89
%91 = add nsw i32 %90, 1
store i32 %91, i32* %89
br label %92
92: ; preds = %82, %75
br label %93
93: ; preds = %92
%94 = load i32, i32* %10
%95 = add nsw i32 %94, 1
store i32 %95, i32* %10
br label %70
96: ; preds = %70
br label %97
97: ; preds = %96
%98 = load i32, i32* %7
%99 = sub nsw i32 %98, 1
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [10 x i32], [10 x i32]* %11, i64 0, i64 %100
%102 = load i32, i32* %101
%103 = load i32, i32* %8
%104 = icmp ne i32 %102, %103
br i1 %104, label %40, label %105
105: ; preds = %97
%106 = load i32*, i32** %9
%107 = call i32 @fclose(i32* %106)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wt\00"
@.str.1 = [34 x i8] c"Can't open codebook text file %s\0A\00"
@.str.2 = [7 x i8] c"%d %d\0A\00"
@.str.3 = [7 x i8] c"%4.0f \00"
define void @create_codebook_text_file(i8* %0, float* nocapture %1, i32 %2, i32 %3) {
%5 = alloca [10 x i32]
%6 = bitcast [10 x i32]* %5 to i8*
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %17
11: ; preds = %9
%12 = zext i32 %2 to i64
%13 = shl nuw nsw i64 %12, 2
br label %17
14: ; preds = %4
%15 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %11, %9
%18 = tail call i64 @pow(i32 %3, i32 %2)
%19 = trunc i64 %18 to i32
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %2, i32 %19)
%21 = add i32 %2, -1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %22
%24 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 0
%25 = icmp sgt i32 %2, 1
%26 = sext i32 %3 to i64
%27 = zext i32 %2 to i64
%28 = zext i32 %21 to i64
br label %29
29: ; preds = %65, %17
br i1 %10, label %30, label %43
30: ; preds = %29, %30
%31 = phi i64 [ %41, %30 ], [ 0, %29 ]
%32 = mul nsw i64 %31, %26
%33 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %31
%34 = load i32, i32* %33
%35 = sext i32 %34 to i64
%36 = add nsw i64 %32, %35
%37 = getelementptr inbounds float, float* %1, i64 %36
%38 = load float, float* %37
%39 = fpext float %38 to double
%40 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %39)
%41 = add nuw nsw i64 %31, 1
%42 = icmp eq i64 %41, %27
br i1 %42, label %43, label %30
43: ; preds = %30, %29
%44 = tail call i32 @fputc(i32 10, i32* %7)
%45 = load i32, i32* %24
%46 = add nsw i32 %45, 1
store i32 %46, i32* %24
br i1 %25, label %47, label %65
47: ; preds = %43, %62
%48 = phi i32 [ %64, %62 ], [ %46, %43 ]
%49 = phi i64 [ %60, %62 ], [ 0, %43 ]
%50 = icmp eq i32 %48, %3
br i1 %50, label %53, label %51
51: ; preds = %47
%52 = add nuw nsw i64 %49, 1
br label %59
53: ; preds = %47
%54 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %49
store i32 0, i32* %54
%55 = add nuw nsw i64 %49, 1
%56 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = add nsw i32 %57, 1
store i32 %58, i32* %56
br label %59
59: ; preds = %51, %53
%60 = phi i64 [ %52, %51 ], [ %55, %53 ]
%61 = icmp eq i64 %60, %28
br i1 %61, label %65, label %62
62: ; preds = %59
%63 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 %60
%64 = load i32, i32* %63
br label %47
65: ; preds = %59, %43
%66 = load i32, i32* %23
%67 = icmp eq i32 %66, %3
br i1 %67, label %68, label %29
68: ; preds = %65
%69 = tail call i32 @fclose(i32* %7)
ret void
}