#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ free(int **);
int *getindices(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int **malloc(int);
int /*<<< orphan*/ printf(char *, int, int, ...);
int **readmergedvalues(int, int *, int, char *);
void allmergedmarspec(int outer, int inner) {
  printf("all merged marspec %d %d", outer, inner);
  struct timeval start, end;
  gettimeofday(&start, NULL);
  char *name = "D:\\temp\\sbg_10m\\merged.mbg";
  int i;
  int *indices = getindices(inner);
  int **values = malloc(sizeof(int *) * inner);
  int ncol = 39;
  for (i = 0; i < outer; i++) {
    int **v = readmergedvalues(inner, indices, ncol, name);
    if (i == 0) {
      values = v;
    } else
      free(v);
  }
  gettimeofday(&end, NULL);
  printf(" took %ld ms to get %d, %d from col 1 and values from %d other "
         "columns\n",
         ((end.tv_sec * 1000 + (end.tv_usec / 1000)) -
          (start.tv_sec * 1000 + (start.tv_usec / 1000))),
         values[0][0], values[2][0], ncol - 1);
  free(values);
}


x86 assembly (clang, -O0):
<allmergedmarspec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    0xe83(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
call   1080 <getindices@plt>
mov    %rax,-0x30(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x27,-0x3c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121d <allmergedmarspec+0xbd>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x3c(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1070 <readmergedvalues@plt>
mov    %rax,-0x48(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1201 <allmergedmarspec+0xa1>
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    120a <allmergedmarspec+0xaa>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
jmp    120f <allmergedmarspec+0xaf>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c7 <allmergedmarspec+0x67>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
imul   $0x3e8,-0x18(%rbp),%esi
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
add    %eax,%esi
imul   $0x3e8,-0x10(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
add    %ecx,%eax
sub    %eax,%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edx
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%ecx
mov    -0x3c(%rbp),%r8d
sub    $0x1,%r8d
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allmergedmarspec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r15d
mov    %edi,%ebp
lea    0xe88(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %r15d,%edi
call   1080 <getindices@plt>
mov    %rax,%rbx
lea    0x0(,%r15,8),%edi
call   1060 <malloc@plt>
test   %ebp,%ebp
jle    1202 <allmergedmarspec+0xa2>
lea    0xe66(%rip),%rcx
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x27,%edx
call   1070 <readmergedvalues@plt>
mov    %rax,%r14
cmp    $0x1,%ebp
je     1205 <allmergedmarspec+0xa5>
add    $0xffffffff,%ebp
lea    0xe44(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x27,%edx
mov    %r12,%rcx
call   1070 <readmergedvalues@plt>
mov    %rax,%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebp
jne    11e0 <allmergedmarspec+0x80>
jmp    1205 <allmergedmarspec+0xa5>
mov    %rax,%r14
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    (%rsp),%eax
movslq 0x4(%rsp),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
movslq 0xc(%rsp),%rdx
imul   $0xffffffffef9db22d,%rdx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x26,%rdx
add    %esi,%edx
add    %ecx,%edx
sub    0x8(%rsp),%eax
imul   $0x3e8,%eax,%esi
add    %edx,%esi
mov    (%r14),%rax
mov    0x10(%r14),%rcx
mov    (%rax),%edx
mov    (%rcx),%ecx
lea    0xdd0(%rip),%rdi
mov    $0x26,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [25 x i8] c"all merged marspec %d %d\00"
@.str.1 = [27 x i8] c"D:\\temp\\sbg_10m\\merged.mbg\00"
@.str.2 = [72 x i8] c" took %ld ms to get %d, %d from col 1 and values from %d other columns\0A\00"
define void @allmergedmarspec(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32**
%11 = alloca i32
%12 = alloca i32**
store i32 %0, i32* %3
store i32 %1, i32* %4
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8** %7
%17 = load i32, i32* %4
%18 = call i32* @getindices(i32 %17)
store i32* %18, i32** %9
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = mul i64 8, %20
%22 = trunc i64 %21 to i32
%23 = call i32** @malloc(i32 %22)
store i32** %23, i32*** %10
store i32 39, i32* %11
store i32 0, i32* %8
br label %24
24: ; preds = %42, %2
%25 = load i32, i32* %8
%26 = load i32, i32* %3
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %45
28: ; preds = %24
%29 = load i32, i32* %4
%30 = load i32*, i32** %9
%31 = load i32, i32* %11
%32 = load i8*, i8** %7
%33 = call i32** @readmergedvalues(i32 %29, i32* %30, i32 %31, i8* %32)
store i32** %33, i32*** %12
%34 = load i32, i32* %8
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %28
%37 = load i32**, i32*** %12
store i32** %37, i32*** %10
br label %41
38: ; preds = %28
%39 = load i32**, i32*** %12
%40 = call i32 @free(i32** %39)
br label %41
41: ; preds = %38, %36
br label %42
42: ; preds = %41
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %24
45: ; preds = %24
%46 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%48 = load i32, i32* %47
%49 = mul nsw i32 %48, 1000
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%51 = load i32, i32* %50
%52 = sdiv i32 %51, 1000
%53 = add nsw i32 %49, %52
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%55 = load i32, i32* %54
%56 = mul nsw i32 %55, 1000
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%58 = load i32, i32* %57
%59 = sdiv i32 %58, 1000
%60 = add nsw i32 %56, %59
%61 = sub nsw i32 %53, %60
%62 = load i32**, i32*** %10
%63 = getelementptr inbounds i32*, i32** %62, i64 0
%64 = load i32*, i32** %63
%65 = getelementptr inbounds i32, i32* %64, i64 0
%66 = load i32, i32* %65
%67 = load i32**, i32*** %10
%68 = getelementptr inbounds i32*, i32** %67, i64 2
%69 = load i32*, i32** %68
%70 = getelementptr inbounds i32, i32* %69, i64 0
%71 = load i32, i32* %70
%72 = load i32, i32* %11
%73 = sub nsw i32 %72, 1
%74 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), i32 %61, i32 %66, i32 %71, i32 %73)
%75 = load i32**, i32*** %10
%76 = call i32 @free(i32** %75)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [25 x i8] c"all merged marspec %d %d\00"
@.str.1 = [27 x i8] c"D:\\temp\\sbg_10m\\merged.mbg\00"
@.str.2 = [72 x i8] c" took %ld ms to get %d, %d from col 1 and values from %d other columns\0A\00"
define void @allmergedmarspec(i32 %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%9 = tail call i32* @getindices(i32 %1)
%10 = shl i32 %1, 3
%11 = tail call i32** @malloc(i32 %10)
%12 = icmp sgt i32 %0, 0
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = tail call i32** @readmergedvalues(i32 %1, i32* %9, i32 39, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %0, 1
br i1 %15, label %22, label %16
16: ; preds = %13, %16
%17 = phi i32 [ %20, %16 ], [ 1, %13 ]
%18 = tail call i32** @readmergedvalues(i32 %1, i32* %9, i32 39, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @free(i32** %18)
%20 = add nuw nsw i32 %17, 1
%21 = icmp eq i32 %20, %0
br i1 %21, label %22, label %16
22: ; preds = %16, %13, %2
%23 = phi i32** [ %11, %2 ], [ %14, %13 ], [ %14, %16 ]
%24 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%28 = load i32, i32* %27
%29 = sdiv i32 %28, 1000
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%33 = load i32, i32* %32
%34 = sdiv i32 %33, -1000
%35 = sub i32 %26, %31
%36 = mul i32 %35, 1000
%37 = add nsw i32 %34, %29
%38 = add i32 %37, %36
%39 = load i32*, i32** %23
%40 = load i32, i32* %39
%41 = getelementptr inbounds i32*, i32** %23, i64 2
%42 = load i32*, i32** %41
%43 = load i32, i32* %42
%44 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), i32 %38, i32 %40, i32 %43, i32 38)
%45 = tail call i32 @free(i32** %23)
ret void
}