#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int findNcameras(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ readCameraParams(int /*<<< orphan*/ *, int,
                                    void (*)(double *, int, double *, int), int,
                                    double *, double *);
int /*<<< orphan*/ readNpointsAndNprojections(int /*<<< orphan*/ *, int *, int,
                                              int *, int, int *);
int /*<<< orphan*/ readPointParamsAndProjections(int /*<<< orphan*/ *, double *,
                                                 int, double *, double *, int,
                                                 int, char *, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void readInitialSBAEstimate(
    char *camsfname, char *ptsfname, int cnp, int pnp, int mnp,
    void (*infilter)(double *pin, int nin, double *pout, int nout), int filecnp,
    int *ncams, int *n3Dpts, int *n2Dprojs, double **motstruct,
    double **initrot, double **imgpts, double **covimgpts, char **vmask) {
  FILE *fpc, *fpp;
  int havecov;
  if ((fpc = fopen(camsfname, "r")) == NULL) {
    fprintf(stderr, "cannot open file %s, exiting\n", camsfname);
    exit(1);
  }
  if ((fpp = fopen(ptsfname, "r")) == NULL) {
    fprintf(stderr, "cannot open file %s, exiting\n", ptsfname);
    exit(1);
  }
  *ncams = findNcameras(fpc);
  readNpointsAndNprojections(fpp, n3Dpts, pnp, n2Dprojs, mnp, &havecov);
  *motstruct =
      (double *)malloc((*ncams * cnp + *n3Dpts * pnp) * sizeof(double));
  if (*motstruct == NULL) {
    fprintf(stderr, "memory allocation for 'motstruct' failed in "
                    "readInitialSBAEstimate()\n");
    exit(1);
  }
  *initrot = (double *)malloc((*ncams * 4) * sizeof(double));
  if (*initrot == NULL) {
    fprintf(
        stderr,
        "memory allocation for 'initrot' failed in readInitialSBAEstimate()\n");
    exit(1);
  }
  *imgpts = (double *)malloc(*n2Dprojs * mnp * sizeof(double));
  if (*imgpts == NULL) {
    fprintf(
        stderr,
        "memory allocation for 'imgpts' failed in readInitialSBAEstimate()\n");
    exit(1);
  }
  if (havecov) {
    *covimgpts = (double *)malloc(*n2Dprojs * mnp * mnp * sizeof(double));
    if (*covimgpts == NULL) {
      fprintf(stderr, "memory allocation for 'covimgpts' failed in "
                      "readInitialSBAEstimate()\n");
      exit(1);
    }
  } else
    *covimgpts = NULL;
  *vmask = (char *)malloc(*n3Dpts * *ncams * sizeof(char));
  if (*vmask == NULL) {
    fprintf(
        stderr,
        "memory allocation for 'vmask' failed in readInitialSBAEstimate()\n");
    exit(1);
  }
  memset(*vmask, 0, *n3Dpts * *ncams * sizeof(char));
  rewind(fpc);
  rewind(fpp);
  readCameraParams(fpc, cnp, infilter, filecnp, *motstruct, *initrot);
  readPointParamsAndProjections(fpp, *motstruct + *ncams * cnp, pnp, *imgpts,
                                *covimgpts, havecov, mnp, *vmask, *ncams);
  fclose(fpc);
  fclose(fpp);
}


x86 assembly (clang, -O0):
<readInitialSBAEstimate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x50(%rbp),%rax
mov    0x48(%rbp),%rax
mov    0x40(%rbp),%rax
mov    0x38(%rbp),%rax
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1234 <readInitialSBAEstimate+0x84>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xdc1(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1277 <readInitialSBAEstimate+0xc7>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1050 <findNcameras@plt>
mov    %eax,%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rdi
mov    0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    0x28(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    -0x3c(%rbp),%r9
call   1030 <readNpointsAndNprojections@plt>
mov    0x18(%rbp),%rax
mov    (%rax),%eax
imul   -0x14(%rbp),%eax
mov    0x20(%rbp),%rcx
mov    (%rcx),%ecx
imul   -0x18(%rbp),%ecx
add    %ecx,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,%rcx
mov    0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1300 <readInitialSBAEstimate+0x150>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
lea    0xd31(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x18(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,%rcx
mov    0x38(%rbp),%rax
mov    %rcx,(%rax)
mov    0x38(%rbp),%rax
cmpq   $0x0,(%rax)
jne    134f <readInitialSBAEstimate+0x19f>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x28(%rbp),%rax
mov    (%rax),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,%rcx
mov    0x40(%rbp),%rax
mov    %rcx,(%rax)
mov    0x40(%rbp),%rax
cmpq   $0x0,(%rax)
jne    139f <readInitialSBAEstimate+0x1ef>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
lea    0xd1c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x3c(%rbp)
je     1402 <readInitialSBAEstimate+0x252>
mov    0x28(%rbp),%rax
mov    (%rax),%eax
imul   -0x1c(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,%rcx
mov    0x48(%rbp),%rax
mov    %rcx,(%rax)
mov    0x48(%rbp),%rax
cmpq   $0x0,(%rax)
jne    13fd <readInitialSBAEstimate+0x24d>
mov    0x2bfd(%rip),%rax
mov    (%rax),%edi
lea    0xd01(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    140d <readInitialSBAEstimate+0x25d>
mov    0x48(%rbp),%rax
movq   $0x0,(%rax)
mov    0x20(%rbp),%rax
mov    (%rax),%eax
mov    0x18(%rbp),%rcx
imul   (%rcx),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,%rcx
mov    0x50(%rbp),%rax
mov    %rcx,(%rax)
mov    0x50(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1460 <readInitialSBAEstimate+0x2b0>
mov    0x2b9a(%rip),%rax
mov    (%rax),%edi
lea    0xce4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x50(%rbp),%rax
mov    (%rax),%rdi
mov    0x20(%rbp),%rax
mov    (%rax),%eax
mov    0x18(%rbp),%rcx
imul   (%rcx),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x30(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x38(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    0x10(%rbp),%ecx
mov    0x30(%rbp),%rax
mov    (%rax),%r8
mov    0x38(%rbp),%rax
mov    (%rax),%r9
call   1090 <readCameraParams@plt>
mov    -0x38(%rbp),%rdi
mov    0x30(%rbp),%rax
mov    (%rax),%rsi
mov    0x18(%rbp),%rax
mov    (%rax),%eax
imul   -0x14(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
mov    0x40(%rbp),%rax
mov    (%rax),%rcx
mov    0x48(%rbp),%rax
mov    (%rax),%r8
mov    -0x3c(%rbp),%r9d
mov    -0x1c(%rbp),%r11d
mov    0x50(%rbp),%rax
mov    (%rax),%r10
mov    0x18(%rbp),%rax
mov    (%rax),%eax
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   10c0 <readPointParamsAndProjections@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readInitialSBAEstimate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x20(%rsp)
mov    %r8,0x10(%rsp)
mov    %ecx,0x8(%rsp)
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe24(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     13e2 <readInitialSBAEstimate+0x232>
lea    0xe0a(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     13f7 <readInitialSBAEstimate+0x247>
mov    %rax,%r13
mov    0x78(%rsp),%r12
mov    0x70(%rsp),%rbx
mov    0x68(%rsp),%r14
mov    0x18(%rsp),%rdi
call   1050 <findNcameras@plt>
mov    %eax,(%r14)
lea    0xc(%rsp),%r9
mov    %r13,%rdi
mov    %rbx,%rsi
mov    0x8(%rsp),%ebp
mov    %ebp,%edx
mov    %r12,%rcx
mov    0x10(%rsp),%r8
call   1030 <readNpointsAndNprojections@plt>
mov    (%r14),%eax
imul   %r15d,%eax
mov    (%rbx),%edi
imul   %ebp,%edi
add    %eax,%edi
shl    $0x3,%edi
call   10a0 <malloc@plt>
mov    0x80(%rsp),%rcx
mov    %rax,(%rcx)
test   %rax,%rax
je     141b <readInitialSBAEstimate+0x26b>
mov    0x88(%rsp),%rbx
mov    (%r14),%edi
shl    $0x5,%edi
call   10a0 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     142d <readInitialSBAEstimate+0x27d>
mov    0x90(%rsp),%rbx
mov    0x10(%rsp),%rax
lea    0x0(,%rax,8),%ebp
mov    0x78(%rsp),%rax
mov    (%rax),%edi
imul   %ebp,%edi
call   10a0 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     143f <readInitialSBAEstimate+0x28f>
mov    0x98(%rsp),%r12
cmpl   $0x0,0xc(%rsp)
je     12fd <readInitialSBAEstimate+0x14d>
imul   0x10(%rsp),%ebp
mov    0x78(%rsp),%rax
imul   (%rax),%ebp
mov    %ebp,%edi
call   10a0 <malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
jne    1305 <readInitialSBAEstimate+0x155>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
jmp    1461 <readInitialSBAEstimate+0x2b1>
movq   $0x0,(%r12)
mov    0xa0(%rsp),%rbp
mov    (%r14),%edi
mov    0x70(%rsp),%rbx
imul   (%rbx),%edi
call   10a0 <malloc@plt>
mov    %rax,0x0(%rbp)
test   %rax,%rax
je     1451 <readInitialSBAEstimate+0x2a1>
mov    (%r14),%edx
imul   (%rbx),%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <rewind@plt>
mov    %r13,%rdi
call   1060 <rewind@plt>
mov    0x80(%rsp),%rbp
mov    0x0(%rbp),%r8
mov    0x88(%rsp),%rax
mov    (%rax),%r9
mov    %rbx,%rdi
mov    %r15d,%esi
mov    0x20(%rsp),%rdx
mov    0x60(%rsp),%ecx
call   1090 <readCameraParams@plt>
mov    (%r14),%eax
imul   %eax,%r15d
movslq %r15d,%rsi
shl    $0x3,%rsi
add    0x0(%rbp),%rsi
mov    0x90(%rsp),%rcx
mov    (%rcx),%rcx
mov    (%r12),%r8
mov    0xc(%rsp),%r9d
sub    $0x8,%rsp
mov    %r13,%rdi
mov    0x10(%rsp),%edx
push   %rax
mov    0xb0(%rsp),%rax
push   (%rax)
push   0x28(%rsp)
call   10c0 <readPointParamsAndProjections@plt>
add    $0x20,%rsp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
lea    0xc10(%rip),%rsi
mov    %rbx,%rdx
jmp    140a <readInitialSBAEstimate+0x25a>
mov    0x2be2(%rip),%rax
mov    (%rax),%edi
lea    0xbfb(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
lea    0xbf5(%rip),%rsi
jmp    1461 <readInitialSBAEstimate+0x2b1>
mov    0x2bac(%rip),%rax
mov    (%rax),%edi
lea    0xc29(%rip),%rsi
jmp    1461 <readInitialSBAEstimate+0x2b1>
mov    0x2b9a(%rip),%rax
mov    (%rax),%edi
lea    0xc5b(%rip),%rsi
jmp    1461 <readInitialSBAEstimate+0x2b1>
mov    0x2b88(%rip),%rax
mov    (%rax),%edi
lea    0xcd2(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"cannot open file %s, exiting\0A\00"
@.str.2 = [70 x i8] c"memory allocation for 'motstruct' failed in readInitialSBAEstimate()\0A\00"
@.str.3 = [68 x i8] c"memory allocation for 'initrot' failed in readInitialSBAEstimate()\0A\00"
@.str.4 = [67 x i8] c"memory allocation for 'imgpts' failed in readInitialSBAEstimate()\0A\00"
@.str.5 = [70 x i8] c"memory allocation for 'covimgpts' failed in readInitialSBAEstimate()\0A\00"
@.str.6 = [66 x i8] c"memory allocation for 'vmask' failed in readInitialSBAEstimate()\0A\00"
define void @readInitialSBAEstimate(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, void (double*, i32, double*, i32)* %5, i32 %6, i32* %7, i32* %8, i32* %9, double** %10, double** %11, double** %12, double** %13, i8** %14) {
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca void (double*, i32, double*, i32)*
%22 = alloca i32
%23 = alloca i32*
%24 = alloca i32*
%25 = alloca i32*
%26 = alloca double**
%27 = alloca double**
%28 = alloca double**
%29 = alloca double**
%30 = alloca i8**
%31 = alloca i32*
%32 = alloca i32*
%33 = alloca i32
store i8* %0, i8** %16
store i8* %1, i8** %17
store i32 %2, i32* %18
store i32 %3, i32* %19
store i32 %4, i32* %20
store void (double*, i32, double*, i32)* %5, void (double*, i32, double*, i32)** %21
store i32 %6, i32* %22
store i32* %7, i32** %23
store i32* %8, i32** %24
store i32* %9, i32** %25
store double** %10, double*** %26
store double** %11, double*** %27
store double** %12, double*** %28
store double** %13, double*** %29
store i8** %14, i8*** %30
%34 = load i8*, i8** %16
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %35, i32** %31
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %15
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %16
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %15
%43 = load i8*, i8** %17
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %44, i32** %32
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %51
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %17
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %42
%52 = load i32*, i32** %31
%53 = call i32 @findNcameras(i32* %52)
%54 = load i32*, i32** %23
store i32 %53, i32* %54
%55 = load i32*, i32** %32
%56 = load i32*, i32** %24
%57 = load i32, i32* %19
%58 = load i32*, i32** %25
%59 = load i32, i32* %20
%60 = call i32 @readNpointsAndNprojections(i32* %55, i32* %56, i32 %57, i32* %58, i32 %59, i32* %33)
%61 = load i32*, i32** %23
%62 = load i32, i32* %61
%63 = load i32, i32* %18
%64 = mul nsw i32 %62, %63
%65 = load i32*, i32** %24
%66 = load i32, i32* %65
%67 = load i32, i32* %19
%68 = mul nsw i32 %66, %67
%69 = add nsw i32 %64, %68
%70 = sext i32 %69 to i64
%71 = mul i64 %70, 8
%72 = trunc i64 %71 to i32
%73 = call i64 @malloc(i32 %72)
%74 = inttoptr i64 %73 to double*
%75 = load double**, double*** %26
store double* %74, double** %75
%76 = load double**, double*** %26
%77 = load double*, double** %76
%78 = icmp eq double* %77, null
br i1 %78, label %79, label %83
79: ; preds = %51
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %51
%84 = load i32*, i32** %23
%85 = load i32, i32* %84
%86 = mul nsw i32 %85, 4
%87 = sext i32 %86 to i64
%88 = mul i64 %87, 8
%89 = trunc i64 %88 to i32
%90 = call i64 @malloc(i32 %89)
%91 = inttoptr i64 %90 to double*
%92 = load double**, double*** %27
store double* %91, double** %92
%93 = load double**, double*** %27
%94 = load double*, double** %93
%95 = icmp eq double* %94, null
br i1 %95, label %96, label %100
96: ; preds = %83
%97 = load i32, i32* @stderr
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %83
%101 = load i32*, i32** %25
%102 = load i32, i32* %101
%103 = load i32, i32* %20
%104 = mul nsw i32 %102, %103
%105 = sext i32 %104 to i64
%106 = mul i64 %105, 8
%107 = trunc i64 %106 to i32
%108 = call i64 @malloc(i32 %107)
%109 = inttoptr i64 %108 to double*
%110 = load double**, double*** %28
store double* %109, double** %110
%111 = load double**, double*** %28
%112 = load double*, double** %111
%113 = icmp eq double* %112, null
br i1 %113, label %114, label %118
114: ; preds = %100
%115 = load i32, i32* @stderr
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0))
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %100
%119 = load i32, i32* %33
%120 = icmp ne i32 %119, 0
br i1 %120, label %121, label %142
121: ; preds = %118
%122 = load i32*, i32** %25
%123 = load i32, i32* %122
%124 = load i32, i32* %20
%125 = mul nsw i32 %123, %124
%126 = load i32, i32* %20
%127 = mul nsw i32 %125, %126
%128 = sext i32 %127 to i64
%129 = mul i64 %128, 8
%130 = trunc i64 %129 to i32
%131 = call i64 @malloc(i32 %130)
%132 = inttoptr i64 %131 to double*
%133 = load double**, double*** %29
store double* %132, double** %133
%134 = load double**, double*** %29
%135 = load double*, double** %134
%136 = icmp eq double* %135, null
br i1 %136, label %137, label %141
137: ; preds = %121
%138 = load i32, i32* @stderr
%139 = call i32 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.5, i64 0, i64 0))
%140 = call i32 @exit(i32 1)
unreachable
141: ; preds = %121
br label %144
142: ; preds = %118
%143 = load double**, double*** %29
store double* null, double** %143
br label %144
144: ; preds = %142, %141
%145 = load i32*, i32** %24
%146 = load i32, i32* %145
%147 = load i32*, i32** %23
%148 = load i32, i32* %147
%149 = mul nsw i32 %146, %148
%150 = sext i32 %149 to i64
%151 = mul i64 %150, 1
%152 = trunc i64 %151 to i32
%153 = call i64 @malloc(i32 %152)
%154 = inttoptr i64 %153 to i8*
%155 = load i8**, i8*** %30
store i8* %154, i8** %155
%156 = load i8**, i8*** %30
%157 = load i8*, i8** %156
%158 = icmp eq i8* %157, null
br i1 %158, label %159, label %163
159: ; preds = %144
%160 = load i32, i32* @stderr
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %160, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.6, i64 0, i64 0))
%162 = call i32 @exit(i32 1)
unreachable
163: ; preds = %144
%164 = load i8**, i8*** %30
%165 = load i8*, i8** %164
%166 = load i32*, i32** %24
%167 = load i32, i32* %166
%168 = load i32*, i32** %23
%169 = load i32, i32* %168
%170 = mul nsw i32 %167, %169
%171 = sext i32 %170 to i64
%172 = mul i64 %171, 1
%173 = trunc i64 %172 to i32
%174 = call i32 @memset(i8* %165, i32 0, i32 %173)
%175 = load i32*, i32** %31
%176 = call i32 @rewind(i32* %175)
%177 = load i32*, i32** %32
%178 = call i32 @rewind(i32* %177)
%179 = load i32*, i32** %31
%180 = load i32, i32* %18
%181 = load void (double*, i32, double*, i32)*, void (double*, i32, double*, i32)** %21
%182 = load i32, i32* %22
%183 = load double**, double*** %26
%184 = load double*, double** %183
%185 = load double**, double*** %27
%186 = load double*, double** %185
%187 = call i32 @readCameraParams(i32* %179, i32 %180, void (double*, i32, double*, i32)* %181, i32 %182, double* %184, double* %186)
%188 = load i32*, i32** %32
%189 = load double**, double*** %26
%190 = load double*, double** %189
%191 = load i32*, i32** %23
%192 = load i32, i32* %191
%193 = load i32, i32* %18
%194 = mul nsw i32 %192, %193
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds double, double* %190, i64 %195
%197 = load i32, i32* %19
%198 = load double**, double*** %28
%199 = load double*, double** %198
%200 = load double**, double*** %29
%201 = load double*, double** %200
%202 = load i32, i32* %33
%203 = load i32, i32* %20
%204 = load i8**, i8*** %30
%205 = load i8*, i8** %204
%206 = load i32*, i32** %23
%207 = load i32, i32* %206
%208 = call i32 @readPointParamsAndProjections(i32* %188, double* %196, i32 %197, double* %199, double* %201, i32 %202, i32 %203, i8* %205, i32 %207)
%209 = load i32*, i32** %31
%210 = call i32 @fclose(i32* %209)
%211 = load i32*, i32** %32
%212 = call i32 @fclose(i32* %211)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"cannot open file %s, exiting\0A\00"
@.str.2 = [70 x i8] c"memory allocation for 'motstruct' failed in readInitialSBAEstimate()\0A\00"
@.str.3 = [68 x i8] c"memory allocation for 'initrot' failed in readInitialSBAEstimate()\0A\00"
@.str.4 = [67 x i8] c"memory allocation for 'imgpts' failed in readInitialSBAEstimate()\0A\00"
@.str.5 = [70 x i8] c"memory allocation for 'covimgpts' failed in readInitialSBAEstimate()\0A\00"
@.str.6 = [66 x i8] c"memory allocation for 'vmask' failed in readInitialSBAEstimate()\0A\00"
define void @readInitialSBAEstimate(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, void (double*, i32, double*, i32)* %5, i32 %6, i32* nocapture %7, i32* %8, i32* %9, double** nocapture %10, double** nocapture %11, double** nocapture %12, double** nocapture %13, i8** nocapture %14) {
%16 = alloca i32
%17 = bitcast i32* %16 to i8*
%18 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %24
%32 = tail call i32 @findNcameras(i32* %18)
store i32 %32, i32* %7
%33 = call i32 @readNpointsAndNprojections(i32* %25, i32* %8, i32 %3, i32* %9, i32 %4, i32* %16)
%34 = load i32, i32* %7
%35 = mul nsw i32 %34, %2
%36 = load i32, i32* %8
%37 = mul nsw i32 %36, %3
%38 = add nsw i32 %37, %35
%39 = shl i32 %38, 3
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to double*
store double* %41, double** %10
%42 = icmp eq i64 %40, 0
br i1 %42, label %43, label %47
43: ; preds = %31
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %31
%48 = load i32, i32* %7
%49 = shl i32 %48, 5
%50 = call i64 @malloc(i32 %49)
%51 = inttoptr i64 %50 to double*
store double* %51, double** %11
%52 = icmp eq i64 %50, 0
br i1 %52, label %53, label %57
53: ; preds = %47
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %47
%58 = load i32, i32* %9
%59 = shl i32 %4, 3
%60 = mul i32 %59, %58
%61 = call i64 @malloc(i32 %60)
%62 = inttoptr i64 %61 to double*
store double* %62, double** %12
%63 = icmp eq i64 %61, 0
br i1 %63, label %64, label %68
64: ; preds = %57
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %57
%69 = load i32, i32* %16
%70 = icmp eq i32 %69, 0
br i1 %70, label %82, label %71
71: ; preds = %68
%72 = load i32, i32* %9
%73 = mul i32 %59, %4
%74 = mul i32 %73, %72
%75 = call i64 @malloc(i32 %74)
%76 = inttoptr i64 %75 to double*
store double* %76, double** %13
%77 = icmp eq i64 %75, 0
br i1 %77, label %78, label %83
78: ; preds = %71
%79 = load i32, i32* @stderr
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.5, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %68
store double* null, double** %13
br label %83
83: ; preds = %71, %82
%84 = load i32, i32* %8
%85 = load i32, i32* %7
%86 = mul nsw i32 %85, %84
%87 = call i64 @malloc(i32 %86)
%88 = inttoptr i64 %87 to i8*
store i8* %88, i8** %14
%89 = icmp eq i64 %87, 0
br i1 %89, label %90, label %94
90: ; preds = %83
%91 = load i32, i32* @stderr
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.6, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %83
%95 = load i32, i32* %8
%96 = load i32, i32* %7
%97 = mul nsw i32 %96, %95
%98 = call i32 @memset(i8* %88, i32 0, i32 %97)
%99 = call i32 @rewind(i32* %18)
%100 = call i32 @rewind(i32* %25)
%101 = load double*, double** %10
%102 = load double*, double** %11
%103 = call i32 @readCameraParams(i32* %18, i32 %2, void (double*, i32, double*, i32)* %5, i32 %6, double* %101, double* %102)
%104 = load double*, double** %10
%105 = load i32, i32* %7
%106 = mul nsw i32 %105, %2
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds double, double* %104, i64 %107
%109 = load double*, double** %12
%110 = load double*, double** %13
%111 = load i32, i32* %16
%112 = load i8*, i8** %14
%113 = call i32 @readPointParamsAndProjections(i32* %25, double* %108, i32 %3, double* %109, double* %110, i32 %111, i32 %4, i8* %112, i32 %105)
%114 = call i32 @fclose(i32* %18)
%115 = call i32 @fclose(i32* %25)
ret void
}