#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*/ fprintf(int /*<<< orphan*/ *, char *, int const, int const);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ write_num(int /*<<< orphan*/ *, float const);
void write_bg(FILE *fp, const int m, const int n, const float *lp) {
  fprintf(fp, "%i %i\n", m, n);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      write_num(fp, lp[i * n + j]);
      fputc(j < n - 1 ? '\t' : '\n', fp);
    }
  }
}


x86 assembly (clang, -O0):
<write_bg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xea9(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e6 <write_bg+0xb6>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11d3 <write_bg+0xa3>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
call   1030 <write_num@plt>
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    $0xa,%eax
mov    $0x9,%ecx
cmp    %esi,%edx
cmovl  %ecx,%eax
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1176 <write_bg+0x46>
jmp    11d8 <write_bg+0xa8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1163 <write_bg+0x33>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_bg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %edx,%ecx
mov    %esi,%r12d
mov    %rdi,%rbx
lea    0xeb0(%rip),%rsi
mov    %r12d,%edx
mov    %rcx,(%rsp)
call   1050 <fprintf@plt>
test   %r12d,%r12d
jle    11e0 <write_bg+0xb0>
mov    (%rsp),%rcx
lea    -0x1(%rcx),%eax
movslq %eax,%rbp
movslq %ecx,%rax
mov    %r12d,%edx
mov    %rdx,0x8(%rsp)
mov    %ecx,%r14d
shl    $0x2,%rax
mov    %rax,0x10(%rsp)
xor    %r12d,%r12d
jmp    11a0 <write_bg+0x70>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12
add    0x10(%rsp),%r15
cmp    0x8(%rsp),%r12
je     11e0 <write_bg+0xb0>
cmpl   $0x0,(%rsp)
jle    1190 <write_bg+0x60>
xor    %r13d,%r13d
nopl   0x0(%rax)
movss  (%r15,%r13,4),%xmm0
mov    %rbx,%rdi
call   1030 <write_num@plt>
xor    %eax,%eax
cmp    %rbp,%r13
setl   %al
mov    $0xa,%edi
sub    %eax,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%r13
cmp    %r13,%r14
jne    11b0 <write_bg+0x80>
jmp    1190 <write_bg+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%i %i\0A\00"
define void @write_bg(i32* %0, i32 %1, i32 %2, float* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca float*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store float* %3, float** %8
%11 = load i32*, i32** %5
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
store i32 0, i32* %9
br label %15
15: ; preds = %49, %4
%16 = load i32, i32* %9
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %52
19: ; preds = %15
store i32 0, i32* %10
br label %20
20: ; preds = %45, %19
%21 = load i32, i32* %10
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %48
24: ; preds = %20
%25 = load i32*, i32** %5
%26 = load float*, float** %8
%27 = load i32, i32* %9
%28 = load i32, i32* %7
%29 = mul nsw i32 %27, %28
%30 = load i32, i32* %10
%31 = add nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds float, float* %26, i64 %32
%34 = load float, float* %33
%35 = call i32 @write_num(i32* %25, float %34)
%36 = load i32, i32* %10
%37 = load i32, i32* %7
%38 = sub nsw i32 %37, 1
%39 = icmp slt i32 %36, %38
%40 = zext i1 %39 to i64
%41 = select i1 %39, i32 9, i32 10
%42 = trunc i32 %41 to i8
%43 = load i32*, i32** %5
%44 = call i32 @fputc(i8 signext %42, i32* %43)
br label %45
45: ; preds = %24
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
store i32 %47, i32* %10
br label %20
48: ; preds = %20
br label %49
49: ; preds = %48
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %15
52: ; preds = %15
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%i %i\0A\00"
define void @write_bg(i32* %0, i32 %1, i32 %2, float* nocapture %3) {
%5 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = icmp sgt i32 %2, 0
%9 = add nsw i32 %2, -1
%10 = sext i32 %9 to i64
%11 = sext i32 %2 to i64
%12 = zext i32 %1 to i64
%13 = zext i32 %2 to i64
br label %14
14: ; preds = %7, %19
%15 = phi i64 [ 0, %7 ], [ %20, %19 ]
br i1 %8, label %16, label %19
16: ; preds = %14
%17 = mul nsw i64 %15, %11
br label %22
18: ; preds = %19, %4
ret void
19: ; preds = %22, %14
%20 = add nuw nsw i64 %15, 1
%21 = icmp eq i64 %20, %12
br i1 %21, label %18, label %14
22: ; preds = %16, %22
%23 = phi i64 [ 0, %16 ], [ %31, %22 ]
%24 = add nsw i64 %23, %17
%25 = getelementptr inbounds float, float* %3, i64 %24
%26 = load float, float* %25
%27 = tail call i32 @write_num(i32* %0, float %26)
%28 = icmp slt i64 %23, %10
%29 = select i1 %28, i8 9, i8 10
%30 = tail call i32 @fputc(i8 signext %29, i32* %0)
%31 = add nuw nsw i64 %23, 1
%32 = icmp eq i64 %31, %13
br i1 %32, label %19, label %22
}