#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/, char *, unsigned long *,
                          unsigned long *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  unsigned long actual_num_hbs = 0;
  unsigned long i = 0;
  unsigned long hb_name = 0;
  unsigned long num_entries = 0;
  unsigned long num_hbs = 0;
  unsigned long num_samples = 0;
  unsigned long sample_name = 0;
  unsigned long prev_hb_name = 0;
  unsigned long mapped_hb_name = 0;
  double count = 0.0;
  fscanf(stdin, "%lu %lu %lu %lu", &actual_num_hbs, &num_hbs, &num_samples,
         &num_entries);
  fprintf(stderr, "%lu\n", actual_num_hbs);
  fprintf(stdout, "%%%%MatrixMarket matrix coordinate real general\n");
  fprintf(stdout, "%lu %lu %lu\n", actual_num_hbs, num_samples, num_entries);
  for (i = 0; i < num_entries; ++i) {
    fscanf(stdin, "%lu %lu %lf", &hb_name, &sample_name, &count);
    if (hb_name == prev_hb_name) {
      fprintf(stdout, "%lu %lu %.5lf\n", mapped_hb_name, sample_name, count);
    } else {
      ++mapped_hb_name;
      fprintf(stderr, "%lu %lu\n", mapped_hb_name, hb_name);
      fprintf(stdout, "%lu %lu %.5lf\n", mapped_hb_name, sample_name, count);
    }
    prev_hb_name = hb_name;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x40(%rbp),%r8
lea    -0x30(%rbp),%r9
mov    $0x0,%al
call   1030 <fscanf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    12da <main+0x1ba>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x48(%rbp),%rcx
lea    -0x60(%rbp),%r8
mov    $0x0,%al
call   1030 <fscanf@plt>
mov    -0x28(%rbp),%rax
cmp    -0x50(%rbp),%rax
jne    1272 <main+0x152>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
mov    -0x48(%rbp),%rcx
movsd  -0x60(%rbp),%xmm0
lea    0xdf4(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
jmp    12c1 <main+0x1a1>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
mov    -0x48(%rbp),%rcx
movsd  -0x60(%rbp),%xmm0
lea    0xda0(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    120a <main+0xea>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movq   $0x0,0x20(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,(%rsp)
movq   $0x0,0x30(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0x30(%rsp),%rcx
lea    0x28(%rsp),%r8
mov    %rsp,%r9
xor    %eax,%eax
call   1030 <fscanf@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    0x20(%rsp),%rdx
lea    0xe9f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e18(%rip),%rbx
mov    (%rbx),%edi
lea    0xe4f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%edi
mov    0x20(%rsp),%rdx
mov    0x28(%rsp),%rcx
mov    (%rsp),%r8
lea    0xe62(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
cmpq   $0x0,(%rsp)
je     128c <main+0x16c>
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0xe58(%rip),%rbx
xor    %ebp,%ebp
xor    %r15d,%r15d
xor    %r14d,%r14d
jmp    1240 <main+0x120>
nopl   0x0(%rax)
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rcx
movsd  0x8(%rsp),%xmm0
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    0x18(%rsp),%r15
add    $0x1,%r14
cmp    (%rsp),%r14
jae    128c <main+0x16c>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
lea    0x18(%rsp),%rdx
mov    %r12,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1030 <fscanf@plt>
mov    0x18(%rsp),%rcx
cmp    %r15,%rcx
je     1210 <main+0xf0>
add    $0x1,%rbp
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1210 <main+0xf0>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [16 x i8] c"%lu %lu %lu %lu\00"
@stderr = global i32 0
@.str.1 = [5 x i8] c"%lu\0A\00"
@stdout = global i32 0
@.str.2 = [49 x i8] c"%%%%MatrixMarket matrix coordinate real general\0A\00"
@.str.3 = [13 x i8] c"%lu %lu %lu\0A\00"
@.str.4 = [12 x i8] c"%lu %lu %lf\00"
@.str.5 = [15 x i8] c"%lu %lu %.5lf\0A\00"
@.str.6 = [9 x i8] c"%lu %lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i64 0, i64* %7
store i64 0, i64* %8
store i64 0, i64* %9
store i64 0, i64* %10
store i64 0, i64* %11
store i64 0, i64* %12
store i64 0, i64* %13
store i64 0, i64* %14
store double 0.000000e+00, double* %15
%16 = load i32, i32* @stdin
%17 = call i32 (i32, i8*, i64*, i64*, ...) @fscanf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64* %6, i64* %10, i64* %11, i64* %9)
%18 = load i32, i32* @stderr
%19 = load i64, i64* %6
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %19)
%21 = load i32, i32* @stdout
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @stdout
%24 = load i64, i64* %6
%25 = load i64, i64* %11
%26 = load i64, i64* %9
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i64 %24, i64 %25, i64 %26)
store i64 0, i64* %7
br label %28
28: ; preds = %58, %2
%29 = load i64, i64* %7
%30 = load i64, i64* %9
%31 = icmp ult i64 %29, %30
br i1 %31, label %32, label %61
32: ; preds = %28
%33 = load i32, i32* @stdin
%34 = call i32 (i32, i8*, i64*, i64*, ...) @fscanf(i32 %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i64* %8, i64* %12, double* %15)
%35 = load i64, i64* %8
%36 = load i64, i64* %13
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %44
38: ; preds = %32
%39 = load i32, i32* @stdout
%40 = load i64, i64* %14
%41 = load i64, i64* %12
%42 = load double, double* %15
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i64 %40, i64 %41, double %42)
br label %56
44: ; preds = %32
%45 = load i64, i64* %14
%46 = add i64 %45, 1
store i64 %46, i64* %14
%47 = load i32, i32* @stderr
%48 = load i64, i64* %14
%49 = load i64, i64* %8
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i64 %48, i64 %49)
%51 = load i32, i32* @stdout
%52 = load i64, i64* %14
%53 = load i64, i64* %12
%54 = load double, double* %15
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i64 %52, i64 %53, double %54)
br label %56
56: ; preds = %44, %38
%57 = load i64, i64* %8
store i64 %57, i64* %13
br label %58
58: ; preds = %56
%59 = load i64, i64* %7
%60 = add i64 %59, 1
store i64 %60, i64* %7
br label %28
61: ; preds = %28
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [16 x i8] c"%lu %lu %lu %lu\00"
@stderr = global i32 0
@.str.1 = [5 x i8] c"%lu\0A\00"
@stdout = global i32 0
@.str.2 = [49 x i8] c"%%%%MatrixMarket matrix coordinate real general\0A\00"
@.str.3 = [13 x i8] c"%lu %lu %lu\0A\00"
@.str.4 = [12 x i8] c"%lu %lu %lf\00"
@.str.5 = [15 x i8] c"%lu %lu %.5lf\0A\00"
@.str.6 = [9 x i8] c"%lu %lu\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca double
%10 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%11 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%12 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%13 = bitcast i64* %6 to i8*
store i64 0, i64* %6
%14 = bitcast i64* %7 to i8*
store i64 0, i64* %7
%15 = bitcast i64* %8 to i8*
store i64 0, i64* %8
%16 = bitcast double* %9 to i8*
store double 0.000000e+00, double* %9
%17 = load i32, i32* @stdin
%18 = call i32 (i32, i8*, i64*, i64*, ...) @fscanf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64* %3, i64* %6, i64* %7, i64* %5)
%19 = load i32, i32* @stderr
%20 = load i64, i64* %3
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %20)
%22 = load i32, i32* @stdout
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @stdout
%25 = load i64, i64* %3
%26 = load i64, i64* %7
%27 = load i64, i64* %5
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i64 %25, i64 %26, i64 %27)
%29 = load i64, i64* %5
%30 = icmp eq i64 %29, 0
br i1 %30, label %58, label %31
31: ; preds = %2, %52
%32 = phi i64 [ %53, %52 ], [ 0, %2 ]
%33 = phi i64 [ %54, %52 ], [ 0, %2 ]
%34 = phi i64 [ %55, %52 ], [ 0, %2 ]
%35 = load i32, i32* @stdin
%36 = call i32 (i32, i8*, i64*, i64*, ...) @fscanf(i32 %35, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i64* %4, i64* %8, double* %9)
%37 = load i64, i64* %4
%38 = icmp eq i64 %37, %33
br i1 %38, label %39, label %44
39: ; preds = %31
%40 = load i32, i32* @stdout
%41 = load i64, i64* %8
%42 = load double, double* %9
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i64 %32, i64 %41, double %42)
br label %52
44: ; preds = %31
%45 = add i64 %32, 1
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i64 %45, i64 %37)
%48 = load i32, i32* @stdout
%49 = load i64, i64* %8
%50 = load double, double* %9
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i64 %45, i64 %49, double %50)
br label %52
52: ; preds = %44, %39
%53 = phi i64 [ %32, %39 ], [ %45, %44 ]
%54 = load i64, i64* %4
%55 = add nuw i64 %34, 1
%56 = load i64, i64* %5
%57 = icmp ult i64 %55, %56
br i1 %57, label %31, label %58
58: ; preds = %52, %2
ret i32 0
}