#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 uint8_t;
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 *, ...);
int /*<<< orphan*/ printf(char *);
void write_metadata(int totalSize, int parityBlockNum, int nativeBlockNum,
                    uint8_t *encodingMatrix) {
  FILE *fp;
  if ((fp = fopen(".METADATA", "wb")) == NULL) {
    printf("Can not open META file!\n");
    exit(0);
  }
  fprintf(fp, "%d\n", totalSize);
  fprintf(fp, "%d %d\n", parityBlockNum, nativeBlockNum);
  int i;
  int j;
  for (i = 0; i < nativeBlockNum; i++) {
    for (j = 0; j < nativeBlockNum; j++) {
      if (i == j) {
        fprintf(fp, "1 ");
      } else {
        fprintf(fp, "0 ");
      }
    }
    fprintf(fp, "\n");
  }
  for (i = 0; i < parityBlockNum; i++) {
    for (j = 0; j < nativeBlockNum; j++) {
      fprintf(fp, "%d ", encodingMatrix[i * nativeBlockNum + j]);
    }
    fprintf(fp, "\n");
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<write_metadata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
lea    0xe94(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1199 <write_metadata+0x49>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1254 <write_metadata+0x104>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1234 <write_metadata+0xe4>
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jne    120f <write_metadata+0xbf>
mov    -0x20(%rbp),%rdi
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1221 <write_metadata+0xd1>
mov    -0x20(%rbp),%rdi
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1226 <write_metadata+0xd6>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e0 <write_metadata+0x90>
mov    -0x20(%rbp),%rdi
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cd <write_metadata+0x7d>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ce <write_metadata+0x17e>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ae <write_metadata+0x15e>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    126e <write_metadata+0x11e>
mov    -0x20(%rbp),%rdi
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    125b <write_metadata+0x10b>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_metadata>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x8(%rsp)
mov    %edx,%r13d
mov    %esi,%r14d
mov    %edi,%r12d
lea    0xe6d(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12d2 <write_metadata+0x162>
mov    %rax,%rbx
lea    0xe5e(%rip),%rsi
xor    %ebp,%ebp
mov    %rax,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe45(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,(%rsp)
mov    %r14d,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %r13d,%r13d
jle    123a <write_metadata+0xca>
lea    0xe2c(%rip),%r12
lea    0xe28(%rip),%r15
nop
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %r14d,%ebp
mov    %r15,%rdi
cmove  %r12,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
add    $0x1,%r14d
cmp    %r14d,%r13d
jne    1200 <write_metadata+0x90>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%ebp
cmp    %r13d,%ebp
jne    11f0 <write_metadata+0x80>
mov    (%rsp),%eax
test   %eax,%eax
mov    0x8(%rsp),%r14
jle    12bc <write_metadata+0x14c>
movslq %r13d,%rcx
mov    %eax,%eax
mov    %rax,0x10(%rsp)
mov    %r13d,%r12d
shl    $0x2,%rcx
mov    %rcx,(%rsp)
lea    0xdb8(%rip),%r15
xor    %eax,%eax
jmp    1291 <write_metadata+0x121>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    0x8(%rsp),%rax
add    $0x1,%rax
add    (%rsp),%r14
cmp    0x10(%rsp),%rax
je     12bc <write_metadata+0x14c>
mov    %rax,0x8(%rsp)
test   %r13d,%r13d
jle    1270 <write_metadata+0x100>
xor    %ebp,%ebp
nopl   (%rax)
mov    (%r14,%rbp,4),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    12a0 <write_metadata+0x130>
jmp    1270 <write_metadata+0x100>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xd45(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c".METADATA\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [25 x i8] c"Can not open META file!\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [7 x i8] c"%d %d\0A\00"
@.str.5 = [3 x i8] c"1 \00"
@.str.6 = [3 x i8] c"0 \00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [4 x i8] c"%d \00"
define void @write_metadata(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%12 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %4
%18 = load i32*, i32** %9
%19 = load i32, i32* %5
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %9
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %22, i32 %23)
store i32 0, i32* %10
br label %25
25: ; preds = %51, %17
%26 = load i32, i32* %10
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %54
29: ; preds = %25
store i32 0, i32* %11
br label %30
30: ; preds = %45, %29
%31 = load i32, i32* %11
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %48
34: ; preds = %30
%35 = load i32, i32* %10
%36 = load i32, i32* %11
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32*, i32** %9
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %44
41: ; preds = %34
%42 = load i32*, i32** %9
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %41, %38
br label %45
45: ; preds = %44
%46 = load i32, i32* %11
%47 = add nsw i32 %46, 1
store i32 %47, i32* %11
br label %30
48: ; preds = %30
%49 = load i32*, i32** %9
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %51
51: ; preds = %48
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %25
54: ; preds = %25
store i32 0, i32* %10
br label %55
55: ; preds = %82, %54
%56 = load i32, i32* %10
%57 = load i32, i32* %6
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %85
59: ; preds = %55
store i32 0, i32* %11
br label %60
60: ; preds = %76, %59
%61 = load i32, i32* %11
%62 = load i32, i32* %7
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %79
64: ; preds = %60
%65 = load i32*, i32** %9
%66 = load i32*, i32** %8
%67 = load i32, i32* %10
%68 = load i32, i32* %7
%69 = mul nsw i32 %67, %68
%70 = load i32, i32* %11
%71 = add nsw i32 %69, %70
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %66, i64 %72
%74 = load i32, i32* %73
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %64
%77 = load i32, i32* %11
%78 = add nsw i32 %77, 1
store i32 %78, i32* %11
br label %60
79: ; preds = %60
%80 = load i32*, i32** %9
%81 = call i32 (i32*, i8*, ...) @fprintf(i32* %80, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %82
82: ; preds = %79
%83 = load i32, i32* %10
%84 = add nsw i32 %83, 1
store i32 %84, i32* %10
br label %55
85: ; preds = %55
%86 = load i32*, i32** %9
%87 = call i32 @fclose(i32* %86)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c".METADATA\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [7 x i8] c"%d %d\0A\00"
@.str.5 = [3 x i8] c"1 \00"
@.str.6 = [3 x i8] c"0 \00"
@.str.8 = [4 x i8] c"%d \00"
@str = [24 x i8] c"Can not open META file!\00"
define void @write_metadata(i32 %0, i32 %1, i32 %2, i32* nocapture %3) {
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %4
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %1, i32 %2)
%13 = icmp sgt i32 %2, 0
br i1 %13, label %14, label %16
14: ; preds = %10, %29
%15 = phi i32 [ %31, %29 ], [ 0, %10 ]
br label %22
16: ; preds = %29, %10
%17 = icmp sgt i32 %1, 0
br i1 %17, label %18, label %49
18: ; preds = %16
%19 = sext i32 %2 to i64
%20 = zext i32 %1 to i64
%21 = zext i32 %2 to i64
br label %33
22: ; preds = %14, %22
%23 = phi i32 [ %27, %22 ], [ 0, %14 ]
%24 = icmp eq i32 %15, %23
%25 = select i1 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0)
%26 = tail call i64 @fwrite(i8* %25, i64 2, i64 1, i32* %5)
%27 = add nuw nsw i32 %23, 1
%28 = icmp eq i32 %27, %2
br i1 %28, label %29, label %22
29: ; preds = %22
%30 = tail call i32 @fputc(i32 10, i32* %5)
%31 = add nuw nsw i32 %15, 1
%32 = icmp eq i32 %31, %2
br i1 %32, label %16, label %14
33: ; preds = %18, %45
%34 = phi i64 [ 0, %18 ], [ %47, %45 ]
br i1 %13, label %35, label %45
35: ; preds = %33
%36 = mul nsw i64 %34, %19
br label %37
37: ; preds = %35, %37
%38 = phi i64 [ 0, %35 ], [ %43, %37 ]
%39 = add nsw i64 %38, %36
%40 = getelementptr inbounds i32, i32* %3, i64 %39
%41 = load i32, i32* %40
%42 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %41)
%43 = add nuw nsw i64 %38, 1
%44 = icmp eq i64 %43, %21
br i1 %44, label %45, label %37
45: ; preds = %37, %33
%46 = tail call i32 @fputc(i32 10, i32* %5)
%47 = add nuw nsw i64 %34, 1
%48 = icmp eq i64 %47, %20
br i1 %48, label %49, label %33
49: ; preds = %45, %16
%50 = tail call i32 @fclose(i32* %5)
ret void
}