#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void save_gamma(const char *filename, double **gamma, int num_docs,
                int num_topics) {
  FILE *fileptr;
  int d, k;
  fileptr = fopen(filename, "w");
  for (d = 0; d < num_docs; d++) {
    fprintf(fileptr, "%5.10f", gamma[d][0]);
    for (k = 1; k < num_topics; k++) {
      fprintf(fileptr, " %5.10f", gamma[d][k]);
    }
    fprintf(fileptr, "\n");
  }
  fclose(fileptr);
}


x86 assembly (clang, -O0):
<save_gamma>:
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    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f7 <save_gamma+0xc7>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  (%rax),%xmm0
lea    0xe7b(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11d7 <save_gamma+0xa7>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe40(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1196 <save_gamma+0x66>
mov    -0x20(%rbp),%rdi
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1161 <save_gamma+0x31>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_gamma>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0xc(%rsp)
mov    %edx,%r15d
mov    %rsi,%rbx
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %r15d,%r15d
jle    11f2 <save_gamma+0xb2>
mov    %r15d,%eax
mov    %rax,0x10(%rsp)
mov    0xc(%rsp),%r15d
xor    %r14d,%r14d
lea    0xe7b(%rip),%r12
jmp    11a8 <save_gamma+0x68>
nopl   0x0(%rax)
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     11f2 <save_gamma+0xb2>
mov    (%rbx,%r14,8),%rax
movsd  (%rax),%xmm0
mov    %rbp,%rdi
lea    0xe49(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
cmpl   $0x2,0xc(%rsp)
jl     1190 <save_gamma+0x50>
mov    $0x1,%r13d
xchg   %ax,%ax
mov    (%rbx,%r14,8),%rax
movsd  (%rax,%r13,8),%xmm0
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r15
jne    11d0 <save_gamma+0x90>
jmp    1190 <save_gamma+0x50>
mov    %rbp,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [7 x i8] c"%5.10f\00"
@.str.2 = [8 x i8] c" %5.10f\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @save_gamma(i8* %0, double** %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca double**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store double** %1, double*** %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
store i32 0, i32* %10
br label %14
14: ; preds = %50, %4
%15 = load i32, i32* %10
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %53
18: ; preds = %14
%19 = load i32*, i32** %9
%20 = load double**, double*** %6
%21 = load i32, i32* %10
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double*, double** %20, i64 %22
%24 = load double*, double** %23
%25 = getelementptr inbounds double, double* %24, i64 0
%26 = load double, double* %25
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %26)
store i32 1, i32* %11
br label %28
28: ; preds = %44, %18
%29 = load i32, i32* %11
%30 = load i32, i32* %8
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %47
32: ; preds = %28
%33 = load i32*, i32** %9
%34 = load double**, double*** %6
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double*, double** %34, i64 %36
%38 = load double*, double** %37
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %42)
br label %44
44: ; preds = %32
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
br label %28
47: ; preds = %28
%48 = load i32*, i32** %9
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %47
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %14
53: ; preds = %14
%54 = load i32*, i32** %9
%55 = call i32 @fclose(i32* %54)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [7 x i8] c"%5.10f\00"
@.str.2 = [8 x i8] c" %5.10f\00"
define void @save_gamma(i8* nocapture %0, double** 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 sgt i32 %2, 0
br i1 %6, label %7, label %29
7: ; preds = %4
%8 = icmp sgt i32 %3, 1
%9 = zext i32 %2 to i64
%10 = zext i32 %3 to i64
br label %11
11: ; preds = %7, %25
%12 = phi i64 [ 0, %7 ], [ %27, %25 ]
%13 = getelementptr inbounds double*, double** %1, i64 %12
%14 = load double*, double** %13
%15 = load double, double* %14
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %15)
br i1 %8, label %17, label %25
17: ; preds = %11, %17
%18 = phi i64 [ %23, %17 ], [ 1, %11 ]
%19 = load double*, double** %13
%20 = getelementptr inbounds double, double* %19, i64 %18
%21 = load double, double* %20
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %21)
%23 = add nuw nsw i64 %18, 1
%24 = icmp eq i64 %23, %10
br i1 %24, label %25, label %17
25: ; preds = %17, %11
%26 = tail call i32 @fputc(i32 10, i32* %5)
%27 = add nuw nsw i64 %12, 1
%28 = icmp eq i64 %27, %9
br i1 %28, label %29, label %11
29: ; preds = %25, %4
%30 = tail call i32 @fclose(i32* %5)
ret void
}