#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 uint16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ atof(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int floor(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, size_t, int, int /*<<< orphan*/ *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int main(int argc, char **argv) {
  if (argc != 5) {
    printf("Usage: %s minlat minlon maxlat maxlon\n", argv[0]);
    return 1;
  }
  int minlon;
  int minlat;
  int maxlon;
  int maxlat;
  minlon = floor(atof(argv[2]));
  minlat = floor(atof(argv[1]));
  maxlon = floor(atof(argv[4]));
  maxlat = floor(atof(argv[3]));
  char name[12];
  FILE *hgt;
  uint16_t *map;
  size_t len;
  len = (2 * (maxlon - minlon + 1) * 1200 * (maxlat - minlat + 1) * 1200);
  map = malloc(len);
  uint16_t *sq;
  sq = malloc(2 * 1201 * 1201);
  int rowlen;
  rowlen = 1200 * (maxlon - minlon + 1);
  for (int lon = 0; lon <= maxlon - minlon; lon++) {
    for (int lat = 0; lat <= maxlat - minlat; lat++) {
      sprintf(name, "N%02dE%03d.hgt", lat + minlat, lon + minlon);
      hgt = fopen(name, "r");
      if (hgt == NULL) {
        printf("File %s not found, exitting, no output produced\n", name);
        return 1;
      }
      printf("Opened %s\n", name);
      fread(sq, 1201 * 1201, 2, hgt);
      for (int llon = 0; llon < 1200; llon++) {
        for (int llat = 0; llat < 1200; llat++) {
          uint16_t height;
          height = sq[(1200 - llat) * 1201 + llon];
          height = (height >> 8) | (height << 8);
          if (height == 32768)
            height = map[rowlen * (1200 * lat + llat) + 1200 * lon + llon - 1];
          map[rowlen * (1200 * lat + llat) + 1200 * lon + llon] = height;
        }
      }
    }
  }
  FILE *OUT;
  OUT = fopen("heights.txt", "w");
  fprintf(OUT, "%d %d %d %d\n", minlon, minlat, maxlon, maxlat);
  for (int lat = 0; lat < 1200 * (maxlat - minlat + 1); lat++) {
    for (int lon = 0; lon < 1200 * (maxlon - minlon + 1); lon++) {
      fprintf(OUT, "%d ", map[rowlen * lat + lon]);
    }
    fprintf(OUT, "\n");
  }
  fclose(OUT);
  OUT = fopen("heights.bin", "w");
  fwrite(&minlon, 1, sizeof(int), OUT);
  fwrite(&minlat, 1, sizeof(int), OUT);
  fwrite(&maxlon, 1, sizeof(int), OUT);
  fwrite(&maxlat, 1, sizeof(int), OUT);
  fwrite(map, len, 1, OUT);
  fclose(OUT);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11e2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2f(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ad <main+0x40d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <atof@plt>
mov    %eax,%edi
call   10c0 <floor@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atof@plt>
mov    %eax,%edi
call   10c0 <floor@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1040 <atof@plt>
mov    %eax,%edi
call   10c0 <floor@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <atof@plt>
mov    %eax,%edi
call   10c0 <floor@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
shl    $0x1,%eax
imul   $0x4b0,%eax,%eax
mov    -0x20(%rbp),%ecx
sub    -0x18(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
imul   $0x4b0,%eax,%eax
cltq
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x2c04c2,%edi
call   1080 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
imul   $0x4b0,%eax,%eax
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jg     1445 <main+0x2a5>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    -0x18(%rbp),%ecx
cmp    %ecx,%eax
jg     1432 <main+0x292>
lea    -0x2c(%rbp),%rdi
mov    -0x5c(%rbp),%edx
add    -0x18(%rbp),%edx
mov    -0x58(%rbp),%ecx
add    -0x14(%rbp),%ecx
lea    0xd49(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x2c(%rbp),%rdi
lea    0xd48(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    131e <main+0x17e>
lea    -0x2c(%rbp),%rsi
lea    0xd2b(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15ad <main+0x40d>
lea    -0x2c(%rbp),%rsi
lea    0xd40(%rip),%rdi
call   1060 <printf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x160261,%esi
mov    $0x2,%edx
call   1030 <fread@plt>
movl   $0x0,-0x60(%rbp)
cmpl   $0x4b0,-0x60(%rbp)
jge    141f <main+0x27f>
movl   $0x0,-0x64(%rbp)
cmpl   $0x4b0,-0x64(%rbp)
jge    140c <main+0x26c>
mov    -0x50(%rbp),%rax
mov    $0x4b0,%ecx
sub    -0x64(%rbp),%ecx
imul   $0x4b1,%ecx,%ecx
add    -0x60(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
sar    $0x8,%eax
mov    -0x68(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x68(%rbp)
cmpl   $0x8000,-0x68(%rbp)
jne    13d5 <main+0x235>
mov    -0x40(%rbp),%rax
mov    -0x54(%rbp),%ecx
imul   $0x4b0,-0x5c(%rbp),%edx
add    -0x64(%rbp),%edx
imul   %edx,%ecx
imul   $0x4b0,-0x58(%rbp),%edx
add    %edx,%ecx
add    -0x60(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%edx
mov    -0x40(%rbp),%rax
mov    -0x54(%rbp),%ecx
imul   $0x4b0,-0x5c(%rbp),%esi
add    -0x64(%rbp),%esi
imul   %esi,%ecx
imul   $0x4b0,-0x58(%rbp),%esi
add    %esi,%ecx
add    -0x60(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1360 <main+0x1c0>
jmp    1411 <main+0x271>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    134c <main+0x1ac>
jmp    1424 <main+0x284>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    12b6 <main+0x116>
jmp    1437 <main+0x297>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    129e <main+0xfe>
lea    0xc28(%rip),%rdi
lea    0xc2d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
lea    0xc0d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    -0x18(%rbp),%ecx
add    $0x1,%ecx
imul   $0x4b0,%ecx,%ecx
cmp    %ecx,%eax
jge    1512 <main+0x372>
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    -0x14(%rbp),%ecx
add    $0x1,%ecx
imul   $0x4b0,%ecx,%ecx
cmp    %ecx,%eax
jge    14f2 <main+0x352>
mov    -0x70(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    -0x54(%rbp),%ecx
imul   -0x74(%rbp),%ecx
add    -0x78(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xbb2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    14a4 <main+0x304>
mov    -0x70(%rbp),%rdi
lea    0xb90(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1483 <main+0x2e3>
mov    -0x70(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xb71(%rip),%rdi
lea    0xb57(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rcx
lea    -0x14(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10b0 <fwrite@plt>
mov    -0x70(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10b0 <fwrite@plt>
mov    -0x70(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10b0 <fwrite@plt>
mov    -0x70(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   10b0 <fwrite@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x70(%rbp),%rcx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    -0x70(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%rbx
cmp    $0x5,%edi
jne    13e2 <main+0x242>
mov    0x10(%rbx),%rdi
call   1040 <atof@plt>
mov    %eax,%edi
call   10c0 <floor@plt>
mov    %eax,%r14d
mov    %eax,0x54(%rsp)
mov    0x8(%rbx),%rdi
call   1040 <atof@plt>
mov    %eax,%edi
call   10c0 <floor@plt>
mov    %eax,%r15d
mov    %eax,0x50(%rsp)
mov    0x20(%rbx),%rdi
call   1040 <atof@plt>
mov    %eax,%edi
call   10c0 <floor@plt>
mov    %eax,%ebp
mov    %eax,0x4c(%rsp)
mov    0x18(%rbx),%rdi
call   1040 <atof@plt>
mov    %eax,%edi
call   10c0 <floor@plt>
mov    %eax,0x48(%rsp)
mov    %ebp,0x40(%rsp)
mov    %r14,0x58(%rsp)
sub    %r14d,%ebp
mov    %eax,0x3c(%rsp)
mov    %eax,%r14d
mov    %r15,0x10(%rsp)
sub    %r15d,%r14d
lea    0x1(%r14),%eax
imul   $0x2bf200,%ebp,%edi
add    $0x2bf200,%edi
mov    %rax,0x28(%rsp)
imul   %eax,%edi
mov    %edi,0x38(%rsp)
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0x2c04c2,%edi
call   1080 <malloc@plt>
imul   $0x4b0,%ebp,%r13d
add    $0x4b0,%r13d
test   %ebp,%ebp
js     1409 <main+0x269>
mov    %rax,%r12
add    $0x1,%ebp
imul   $0x4b0,%r13d,%eax
mov    %eax,0x20(%rsp)
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    %r14,0x60(%rsp)
mov    %ebp,0x44(%rsp)
jmp    12cd <main+0x12d>
nopl   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rcx
add    $0x1,%ecx
mov    0x8(%rsp),%rax
add    $0x4b0,%eax
mov    %rax,0x8(%rsp)
mov    0x44(%rsp),%ebp
mov    %rcx,0x18(%rsp)
cmp    %ebp,%ecx
mov    0x60(%rsp),%r14
je     1409 <main+0x269>
test   %r14d,%r14d
lea    0x6c(%rsp),%rbp
js     12a0 <main+0x100>
mov    0x58(%rsp),%rax
mov    0x18(%rsp),%rcx
add    %ecx,%eax
mov    %eax,0x30(%rsp)
mov    0x8(%rsp),%rax
mov    %eax,%r15d
xor    %r14d,%r14d
jmp    1315 <main+0x175>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r14
add    0x20(%rsp),%r15d
cmp    0x28(%rsp),%r14
lea    0x6c(%rsp),%rbp
je     12a0 <main+0x100>
mov    0x10(%rsp),%rax
lea    (%rax,%r14,1),%edx
mov    %rbp,%rdi
lea    0xcff(%rip),%rsi
mov    0x30(%rsp),%ecx
call   10a0 <sprintf@plt>
mov    %rbp,%rdi
lea    0xcfb(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     13ee <main+0x24e>
mov    %rbp,%rsi
mov    %rax,%rbp
lea    0xd13(%rip),%rdi
call   1060 <printf@plt>
mov    %r12,%rdi
mov    $0x160261,%esi
mov    $0x2,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
mov    %r12,%rax
mov    %r15d,%r8d
xor    %edx,%edx
jmp    1399 <main+0x1f9>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rdx
add    $0x1,%r8d
add    $0x4,%rax
cmp    $0x4b0,%rdx
je     1300 <main+0x160>
mov    $0x57f6c0,%esi
mov    %r8d,%edi
jmp    13c2 <main+0x222>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %edi,%rcx
mov    %ebp,(%rbx,%rcx,4)
add    %r13d,%edi
add    $0xffffffffffffed3c,%rsi
je     1380 <main+0x1e0>
mov    (%rax,%rsi,1),%ebp
mov    %ebp,%ecx
sar    $0x8,%ecx
shl    $0x8,%ebp
or     %ecx,%ebp
cmp    $0x8000,%ebp
jne    13b0 <main+0x210>
lea    -0x1(%rdi),%ecx
movslq %ecx,%rcx
mov    (%rbx,%rcx,4),%ebp
jmp    13b0 <main+0x210>
mov    (%rbx),%rsi
lea    0xc14(%rip),%rdi
jmp    13fa <main+0x25a>
lea    0xc43(%rip),%rdi
lea    0x6c(%rsp),%rsi
call   1060 <printf@plt>
mov    $0x1,%eax
jmp    15a6 <main+0x406>
movslq 0x38(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0xc5a(%rip),%rdi
lea    0xc5f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0xc52(%rip),%rsi
mov    %rax,%rdi
mov    0x58(%rsp),%rdx
mov    0x10(%rsp),%rcx
mov    0x40(%rsp),%r8d
mov    0x3c(%rsp),%r9d
xor    %eax,%eax
call   1070 <fprintf@plt>
imul   $0x4b0,%r14d,%eax
add    $0x4b0,%eax
test   %eax,%eax
jle    150d <main+0x36d>
movslq %r13d,%rcx
mov    %eax,%eax
mov    %rax,0x20(%rsp)
mov    %r13d,%eax
mov    %rax,0x10(%rsp)
shl    $0x2,%rcx
mov    %rcx,0x28(%rsp)
mov    %rbx,%r14
xor    %eax,%eax
jmp    14be <main+0x31e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x1,%esi
mov    $0x1,%edx
lea    0xbec(%rip),%rdi
mov    %rcx,%r15
call   10b0 <fwrite@plt>
mov    0x30(%rsp),%rax
add    $0x1,%rax
add    0x28(%rsp),%r14
cmp    0x20(%rsp),%rax
je     150d <main+0x36d>
mov    %rax,0x30(%rsp)
test   %r13d,%r13d
lea    0xbc2(%rip),%r12
mov    %r15,%rcx
jle    1490 <main+0x2f0>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%r15,4),%edx
mov    %rcx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
mov    %r14,%rbp
mov    %rcx,%r14
call   1070 <fprintf@plt>
mov    0x10(%rsp),%rax
mov    %r14,%rcx
mov    %rbp,%r14
add    $0x1,%r15
cmp    %r15,%rax
jne    14e0 <main+0x340>
jmp    1490 <main+0x2f0>
mov    %r15,%rdi
call   1050 <fclose@plt>
lea    0xb77(%rip),%rdi
lea    0xb5d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbp
lea    0x54(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
lea    0x50(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
lea    0x4c(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
lea    0x48(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
mov    $0x1,%edx
mov    %rbp,%rcx
call   10b0 <fwrite@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Usage: %s minlat minlon maxlat maxlon\0A\00"
@.str.1 = [15 x i8] c"N%02dE%03d.hgt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [49 x i8] c"File %s not found, exitting, no output produced\0A\00"
@.str.4 = [11 x i8] c"Opened %s\0A\00"
@.str.5 = [12 x i8] c"heights.txt\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [13 x i8] c"%d %d %d %d\0A\00"
@.str.8 = [4 x i8] c"%d \00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [12 x i8] c"heights.bin\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [12 x i8]
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i64
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32*
%22 = alloca i32
%23 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 5
br i1 %25, label %26, label %31
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %29)
store i32 1, i32* %3
br label %245
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @atof(i8* %34)
%36 = call i32 @floor(i32 %35)
store i32 %36, i32* %6
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @atof(i8* %39)
%41 = call i32 @floor(i32 %40)
store i32 %41, i32* %7
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 4
%44 = load i8*, i8** %43
%45 = call i32 @atof(i8* %44)
%46 = call i32 @floor(i32 %45)
store i32 %46, i32* %8
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 @atof(i8* %49)
%51 = call i32 @floor(i32 %50)
store i32 %51, i32* %9
%52 = load i32, i32* %8
%53 = load i32, i32* %6
%54 = sub nsw i32 %52, %53
%55 = add nsw i32 %54, 1
%56 = mul nsw i32 2, %55
%57 = mul nsw i32 %56, 1200
%58 = load i32, i32* %9
%59 = load i32, i32* %7
%60 = sub nsw i32 %58, %59
%61 = add nsw i32 %60, 1
%62 = mul nsw i32 %57, %61
%63 = mul nsw i32 %62, 1200
%64 = sext i32 %63 to i64
store i64 %64, i64* %13
%65 = load i64, i64* %13
%66 = trunc i64 %65 to i32
%67 = call i32* @malloc(i32 %66)
store i32* %67, i32** %12
%68 = call i32* @malloc(i32 2884802)
store i32* %68, i32** %14
%69 = load i32, i32* %8
%70 = load i32, i32* %6
%71 = sub nsw i32 %69, %70
%72 = add nsw i32 %71, 1
%73 = mul nsw i32 1200, %72
store i32 %73, i32* %15
store i32 0, i32* %16
br label %74
74: ; preds = %178, %31
%75 = load i32, i32* %16
%76 = load i32, i32* %8
%77 = load i32, i32* %6
%78 = sub nsw i32 %76, %77
%79 = icmp sle i32 %75, %78
br i1 %79, label %80, label %181
80: ; preds = %74
store i32 0, i32* %17
br label %81
81: ; preds = %174, %80
%82 = load i32, i32* %17
%83 = load i32, i32* %9
%84 = load i32, i32* %7
%85 = sub nsw i32 %83, %84
%86 = icmp sle i32 %82, %85
br i1 %86, label %87, label %177
87: ; preds = %81
%88 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%89 = load i32, i32* %17
%90 = load i32, i32* %7
%91 = add nsw i32 %89, %90
%92 = load i32, i32* %16
%93 = load i32, i32* %6
%94 = add nsw i32 %92, %93
%95 = call i32 @sprintf(i8* %88, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %91, i32 %94)
%96 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%97 = call i32* @fopen(i8* %96, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %97, i32** %11
%98 = load i32*, i32** %11
%99 = icmp eq i32* %98, null
br i1 %99, label %100, label %103
100: ; preds = %87
%101 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%102 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i8* %101)
store i32 1, i32* %3
br label %245
103: ; preds = %87
%104 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%105 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %104)
%106 = load i32*, i32** %14
%107 = load i32*, i32** %11
%108 = call i32 @fread(i32* %106, i32 1442401, i32 2, i32* %107)
store i32 0, i32* %18
br label %109
109: ; preds = %170, %103
%110 = load i32, i32* %18
%111 = icmp slt i32 %110, 1200
br i1 %111, label %112, label %173
112: ; preds = %109
store i32 0, i32* %19
br label %113
113: ; preds = %166, %112
%114 = load i32, i32* %19
%115 = icmp slt i32 %114, 1200
br i1 %115, label %116, label %169
116: ; preds = %113
%117 = load i32*, i32** %14
%118 = load i32, i32* %19
%119 = sub nsw i32 1200, %118
%120 = mul nsw i32 %119, 1201
%121 = load i32, i32* %18
%122 = add nsw i32 %120, %121
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds i32, i32* %117, i64 %123
%125 = load i32, i32* %124
store i32 %125, i32* %20
%126 = load i32, i32* %20
%127 = ashr i32 %126, 8
%128 = load i32, i32* %20
%129 = shl i32 %128, 8
%130 = or i32 %127, %129
store i32 %130, i32* %20
%131 = load i32, i32* %20
%132 = icmp eq i32 %131, 32768
br i1 %132, label %133, label %150
133: ; preds = %116
%134 = load i32*, i32** %12
%135 = load i32, i32* %15
%136 = load i32, i32* %17
%137 = mul nsw i32 1200, %136
%138 = load i32, i32* %19
%139 = add nsw i32 %137, %138
%140 = mul nsw i32 %135, %139
%141 = load i32, i32* %16
%142 = mul nsw i32 1200, %141
%143 = add nsw i32 %140, %142
%144 = load i32, i32* %18
%145 = add nsw i32 %143, %144
%146 = sub nsw i32 %145, 1
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds i32, i32* %134, i64 %147
%149 = load i32, i32* %148
store i32 %149, i32* %20
br label %150
150: ; preds = %133, %116
%151 = load i32, i32* %20
%152 = load i32*, i32** %12
%153 = load i32, i32* %15
%154 = load i32, i32* %17
%155 = mul nsw i32 1200, %154
%156 = load i32, i32* %19
%157 = add nsw i32 %155, %156
%158 = mul nsw i32 %153, %157
%159 = load i32, i32* %16
%160 = mul nsw i32 1200, %159
%161 = add nsw i32 %158, %160
%162 = load i32, i32* %18
%163 = add nsw i32 %161, %162
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds i32, i32* %152, i64 %164
store i32 %151, i32* %165
br label %166
166: ; preds = %150
%167 = load i32, i32* %19
%168 = add nsw i32 %167, 1
store i32 %168, i32* %19
br label %113
169: ; preds = %113
br label %170
170: ; preds = %169
%171 = load i32, i32* %18
%172 = add nsw i32 %171, 1
store i32 %172, i32* %18
br label %109
173: ; preds = %109
br label %174
174: ; preds = %173
%175 = load i32, i32* %17
%176 = add nsw i32 %175, 1
store i32 %176, i32* %17
br label %81
177: ; preds = %81
br label %178
178: ; preds = %177
%179 = load i32, i32* %16
%180 = add nsw i32 %179, 1
store i32 %180, i32* %16
br label %74
181: ; preds = %74
%182 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %182, i32** %21
%183 = load i32*, i32** %21
%184 = load i32, i32* %6
%185 = load i32, i32* %7
%186 = load i32, i32* %8
%187 = load i32, i32* %9
%188 = call i32 (i32*, i8*, ...) @fprintf(i32* %183, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %184, i32 %185, i32 %186, i32 %187)
store i32 0, i32* %22
br label %189
189: ; preds = %224, %181
%190 = load i32, i32* %22
%191 = load i32, i32* %9
%192 = load i32, i32* %7
%193 = sub nsw i32 %191, %192
%194 = add nsw i32 %193, 1
%195 = mul nsw i32 1200, %194
%196 = icmp slt i32 %190, %195
br i1 %196, label %197, label %227
197: ; preds = %189
store i32 0, i32* %23
br label %198
198: ; preds = %218, %197
%199 = load i32, i32* %23
%200 = load i32, i32* %8
%201 = load i32, i32* %6
%202 = sub nsw i32 %200, %201
%203 = add nsw i32 %202, 1
%204 = mul nsw i32 1200, %203
%205 = icmp slt i32 %199, %204
br i1 %205, label %206, label %221
206: ; preds = %198
%207 = load i32*, i32** %21
%208 = load i32*, i32** %12
%209 = load i32, i32* %15
%210 = load i32, i32* %22
%211 = mul nsw i32 %209, %210
%212 = load i32, i32* %23
%213 = add nsw i32 %211, %212
%214 = sext i32 %213 to i64
%215 = getelementptr inbounds i32, i32* %208, i64 %214
%216 = load i32, i32* %215
%217 = call i32 (i32*, i8*, ...) @fprintf(i32* %207, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %216)
br label %218
218: ; preds = %206
%219 = load i32, i32* %23
%220 = add nsw i32 %219, 1
store i32 %220, i32* %23
br label %198
221: ; preds = %198
%222 = load i32*, i32** %21
%223 = call i32 (i32*, i8*, ...) @fprintf(i32* %222, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %224
224: ; preds = %221
%225 = load i32, i32* %22
%226 = add nsw i32 %225, 1
store i32 %226, i32* %22
br label %189
227: ; preds = %189
%228 = load i32*, i32** %21
%229 = call i32 @fclose(i32* %228)
%230 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %230, i32** %21
%231 = load i32*, i32** %21
%232 = call i32 @fwrite(i32* %6, i64 1, i32 4, i32* %231)
%233 = load i32*, i32** %21
%234 = call i32 @fwrite(i32* %7, i64 1, i32 4, i32* %233)
%235 = load i32*, i32** %21
%236 = call i32 @fwrite(i32* %8, i64 1, i32 4, i32* %235)
%237 = load i32*, i32** %21
%238 = call i32 @fwrite(i32* %9, i64 1, i32 4, i32* %237)
%239 = load i32*, i32** %12
%240 = load i64, i64* %13
%241 = load i32*, i32** %21
%242 = call i32 @fwrite(i32* %239, i64 %240, i32 1, i32* %241)
%243 = load i32*, i32** %21
%244 = call i32 @fclose(i32* %243)
br label %245
245: ; preds = %227, %100, %26
%246 = load i32, i32* %3
ret i32 %246
}

LLVM IR (-O2):
@.str = [39 x i8] c"Usage: %s minlat minlon maxlat maxlon\0A\00"
@.str.1 = [15 x i8] c"N%02dE%03d.hgt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [49 x i8] c"File %s not found, exitting, no output produced\0A\00"
@.str.4 = [11 x i8] c"Opened %s\0A\00"
@.str.5 = [12 x i8] c"heights.txt\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [13 x i8] c"%d %d %d %d\0A\00"
@.str.8 = [4 x i8] c"%d \00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [12 x i8] c"heights.bin\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [12 x i8]
%8 = icmp eq i32 %0, 5
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %150
12: ; preds = %2
%13 = bitcast i32* %3 to i8*
%14 = bitcast i32* %4 to i8*
%15 = bitcast i32* %5 to i8*
%16 = bitcast i32* %6 to i8*
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @atof(i8* %18)
%20 = tail call i32 @floor(i32 %19)
store i32 %20, i32* %3
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call i32 @atof(i8* %22)
%24 = tail call i32 @floor(i32 %23)
store i32 %24, i32* %4
%25 = getelementptr inbounds i8*, i8** %1, i64 4
%26 = load i8*, i8** %25
%27 = tail call i32 @atof(i8* %26)
%28 = tail call i32 @floor(i32 %27)
store i32 %28, i32* %5
%29 = getelementptr inbounds i8*, i8** %1, i64 3
%30 = load i8*, i8** %29
%31 = tail call i32 @atof(i8* %30)
%32 = tail call i32 @floor(i32 %31)
store i32 %32, i32* %6
%33 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%34 = sub nsw i32 %28, %20
%35 = sub nsw i32 %32, %24
%36 = add nsw i32 %35, 1
%37 = mul i32 %34, 2880000
%38 = add i32 %37, 2880000
%39 = mul i32 %38, %36
%40 = sext i32 %39 to i64
%41 = tail call i32* @malloc(i32 %39)
%42 = tail call i32* @malloc(i32 2884802)
%43 = mul i32 %34, 1200
%44 = add i32 %43, 1200
%45 = icmp slt i32 %34, 0
br i1 %45, label %112, label %46
46: ; preds = %12
%47 = icmp slt i32 %35, 0
%48 = add i32 %32, 1
%49 = sub i32 %48, %24
%50 = add i32 %28, 1
%51 = sub i32 %50, %20
%52 = zext i32 %49 to i64
br label %53
53: ; preds = %46, %107
%54 = phi i32 [ 0, %46 ], [ %108, %107 ]
br i1 %47, label %107, label %55
55: ; preds = %53
%56 = add nsw i32 %54, %20
%57 = mul nsw i32 %54, 1200
%58 = add nsw i32 %57, -1
br label %59
59: ; preds = %55, %75
%60 = phi i64 [ 0, %55 ], [ %76, %75 ]
%61 = trunc i64 %60 to i32
%62 = add i32 %24, %61
%63 = call i32 @sprintf(i8* %33, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %62, i32 %56)
%64 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%65 = icmp eq i32* %64, null
br i1 %65, label %110, label %66
66: ; preds = %59
%67 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%68 = call i32 @fread(i32* %42, i32 1442401, i32 2, i32* %64)
%69 = mul nuw nsw i64 %60, 1200
br label %70
70: ; preds = %66, %78
%71 = phi i64 [ 0, %66 ], [ %79, %78 ]
%72 = trunc i64 %71 to i32
%73 = add nuw i32 %57, %72
%74 = add i32 %58, %72
br label %81
75: ; preds = %78
%76 = add nuw nsw i64 %60, 1
%77 = icmp eq i64 %76, %52
br i1 %77, label %107, label %59
78: ; preds = %100
%79 = add nuw nsw i64 %71, 1
%80 = icmp eq i64 %79, 1200
br i1 %80, label %75, label %70
81: ; preds = %70, %100
%82 = phi i64 [ 0, %70 ], [ %105, %100 ]
%83 = sub nuw nsw i64 1200, %82
%84 = mul nuw nsw i64 %83, 1201
%85 = add nuw nsw i64 %84, %71
%86 = getelementptr inbounds i32, i32* %42, i64 %85
%87 = load i32, i32* %86
%88 = ashr i32 %87, 8
%89 = shl i32 %87, 8
%90 = or i32 %88, %89
%91 = icmp eq i32 %90, 32768
%92 = add nuw nsw i64 %82, %69
%93 = trunc i64 %92 to i32
%94 = mul i32 %44, %93
br i1 %91, label %95, label %100
95: ; preds = %81
%96 = add i32 %74, %94
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i32, i32* %41, i64 %97
%99 = load i32, i32* %98
br label %100
100: ; preds = %81, %95
%101 = phi i32 [ %99, %95 ], [ %90, %81 ]
%102 = add i32 %73, %94
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i32, i32* %41, i64 %103
store i32 %101, i32* %104
%105 = add nuw nsw i64 %82, 1
%106 = icmp eq i64 %105, 1200
br i1 %106, label %78, label %81
107: ; preds = %75, %53
%108 = add nuw i32 %54, 1
%109 = icmp eq i32 %108, %51
br i1 %109, label %112, label %53
110: ; preds = %59
%111 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %148
112: ; preds = %107, %12
%113 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%114 = call i32 (i32*, i8*, ...) @fprintf(i32* %113, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %20, i32 %24, i32 %28, i32 %32)
%115 = mul i32 %35, 1200
%116 = add i32 %115, 1200
%117 = icmp sgt i32 %116, 0
br i1 %117, label %118, label %127
118: ; preds = %112
%119 = icmp sgt i32 %44, 0
%120 = sext i32 %44 to i64
%121 = zext i32 %116 to i64
%122 = zext i32 %44 to i64
br label %123
123: ; preds = %118, %136
%124 = phi i64 [ 0, %118 ], [ %138, %136 ]
br i1 %119, label %125, label %136
125: ; preds = %123
%126 = mul nsw i64 %124, %120
br label %140
127: ; preds = %136, %112
%128 = call i32 @fclose(i32* %113)
%129 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%130 = call i32 @fwrite(i32* %3, i64 1, i32 4, i32* %129)
%131 = call i32 @fwrite(i32* %4, i64 1, i32 4, i32* %129)
%132 = call i32 @fwrite(i32* %5, i64 1, i32 4, i32* %129)
%133 = call i32 @fwrite(i32* %6, i64 1, i32 4, i32* %129)
%134 = call i32 @fwrite(i32* %41, i64 %40, i32 1, i32* %129)
%135 = call i32 @fclose(i32* %129)
br label %148
136: ; preds = %140, %123
%137 = call i64 bitcast (i32 (i32*, i64, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i64 1, i64 1, i32* %113)
%138 = add nuw nsw i64 %124, 1
%139 = icmp eq i64 %138, %121
br i1 %139, label %127, label %123
140: ; preds = %125, %140
%141 = phi i64 [ 0, %125 ], [ %146, %140 ]
%142 = add nsw i64 %141, %126
%143 = getelementptr inbounds i32, i32* %41, i64 %142
%144 = load i32, i32* %143
%145 = call i32 (i32*, i8*, ...) @fprintf(i32* %113, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %144)
%146 = add nuw nsw i64 %141, 1
%147 = icmp eq i64 %146, %122
br i1 %147, label %136, label %140
148: ; preds = %110, %127
%149 = phi i32 [ 1, %110 ], [ 0, %127 ]
br label %150
150: ; preds = %148, %9
%151 = phi i32 [ 1, %9 ], [ %149, %148 ]
ret i32 %151
}