main(argc, argv) int argc;
char *argv[];
{
  int i, n;
  char mcname[1000];
  if (argc != 3) {
    printf("Usage:\n");
    printf("   sample yourfile nnnn\n");
    printf("Where:\n");
    printf("   yourfile is the filename of your data set to read.\n");
    printf("   nnnn is the number of the McIDAS file to write.\n");
    printf("Example:\n");
    printf("   sample MODEL.DATA 104\n");
    printf("       This will convert your file MODEL.DATA to the McIDAS\n");
    printf("       grid file named GR3D0104.\n");
    exit(0);
  }
  read_grid(argv[1]);
  n = atoi(argv[2]);
  if (n < 1 || n > 9999) {
    printf("Error: The McIDAS grid file number must be between 1 and 9999\n");
    exit(0);
  }
  sprintf(mcname, "GR3D%04d", n);
  write_gridfile(mcname);
  print_header(mcname);
  for (i = 1; i < 5; i++) {
    printf("\ngrid %d:\n", i);
    print_gridinfo(mcname, i);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1228 <main+0xa8>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x0,%al
call   1040 <read_grid@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x0,%al
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jl     1260 <main+0xe0>
cmpl   $0x270f,-0x18(%rbp)
jle    1275 <main+0xf5>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    -0x400(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xed0(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x400(%rbp),%rdi
mov    $0x0,%al
call   1050 <write_gridfile@plt>
lea    -0x400(%rbp),%rdi
mov    $0x0,%al
call   1070 <print_header@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    12ea <main+0x16a>
mov    -0x14(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x0,%al
call   1060 <print_gridinfo@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12b0 <main+0x130>
mov    -0x4(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
cmp    $0x3,%edi
jne    1284 <main+0xf4>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
xor    %eax,%eax
call   1050 <read_grid@plt>
mov    0x10(%rbx),%rdi
xor    %eax,%eax
call   1090 <atoi@plt>
lea    -0x2710(%rax),%ecx
cmp    $0xffffd8f0,%ecx
jbe    12ed <main+0x15d>
lea    0xe2b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <write_gridfile@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <print_header@plt>
lea    0xe0a(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1070 <print_gridinfo@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1070 <print_gridinfo@plt>
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1070 <print_gridinfo@plt>
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1070 <print_gridinfo@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdc7(%rip),%rdi
call   1030 <puts@plt>
lea    0xdc2(%rip),%rdi
call   1030 <puts@plt>
lea    0xdce(%rip),%rdi
call   1030 <puts@plt>
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe17(%rip),%rdi
call   1030 <puts@plt>
lea    0xe24(%rip),%rdi
call   1030 <puts@plt>
lea    0xe54(%rip),%rdi
jmp    12f4 <main+0x164>
lea    0xd20(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"Usage:\0A\00"
@.str.1 = [25 x i8] c" sample yourfile nnnn\0A\00"
@.str.2 = [8 x i8] c"Where:\0A\00"
@.str.3 = [55 x i8] c" yourfile is the filename of your data set to read.\0A\00"
@.str.4 = [52 x i8] c" nnnn is the number of the McIDAS file to write.\0A\00"
@.str.5 = [10 x i8] c"Example:\0A\00"
@.str.6 = [26 x i8] c" sample MODEL.DATA 104\0A\00"
@.str.7 = [61 x i8] c" This will convert your file MODEL.DATA to the McIDAS\0A\00"
@.str.8 = [34 x i8] c" grid file named GR3D0104.\0A\00"
@.str.9 = [63 x i8] c"Error: The McIDAS grid file number must be between 1 and 9999\0A\00"
@.str.10 = [9 x i8] c"GR3D%04d\00"
@.str.11 = [11 x i8] c"\0Agrid %d:\0A\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 [1000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.7, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0))
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) bitcast (i32 (...)* @read_grid to i32 (i8*, ...)*)(i8* %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 1
br i1 %31, label %35, label %32
32: ; preds = %21
%33 = load i32, i32* %7
%34 = icmp sgt i32 %33, 9999
br i1 %34, label %35, label %37
35: ; preds = %32, %21
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.9, i64 0, i64 0))
unreachable
37: ; preds = %32
%38 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%39 = load i32, i32* %7
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%42 = call i32 (i8*, ...) bitcast (i32 (...)* @write_gridfile to i32 (i8*, ...)*)(i8* %41)
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%44 = call i32 (i8*, ...) bitcast (i32 (...)* @print_header to i32 (i8*, ...)*)(i8* %43)
store i32 1, i32* %6
br label %45
45: ; preds = %54, %37
%46 = load i32, i32* %6
%47 = icmp slt i32 %46, 5
br i1 %47, label %48, label %57
48: ; preds = %45
%49 = load i32, i32* %6
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%52 = load i32, i32* %6
%53 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_gridinfo to i32 (i8*, i32, ...)*)(i8* %51, i32 %52)
br label %54
54: ; preds = %48
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %45
57: ; preds = %45
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str.10 = [9 x i8] c"GR3D%04d\00"
@.str.11 = [11 x i8] c"\0Agrid %d:\0A\00"
@str = [62 x i8] c"Error: The McIDAS grid file number must be between 1 and 9999\00"
@str.12 = [7 x i8] c"Usage:\00"
@str.13 = [24 x i8] c" sample yourfile nnnn\00"
@str.14 = [7 x i8] c"Where:\00"
@str.15 = [54 x i8] c" yourfile is the filename of your data set to read.\00"
@str.16 = [51 x i8] c" nnnn is the number of the McIDAS file to write.\00"
@str.17 = [9 x i8] c"Example:\00"
@str.18 = [25 x i8] c" sample MODEL.DATA 104\00"
@str.19 = [60 x i8] c" This will convert your file MODEL.DATA to the McIDAS\00"
@str.20 = [33 x i8] c" grid file named GR3D0104.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.12, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.13, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.14, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.15, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.16, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.17, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.18, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.19, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.20, i64 0, i64 0))
tail call void @exit(i32 0)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 (i8*, ...) bitcast (i32 (...)* @read_grid to i32 (i8*, ...)*)(i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %21)
%23 = add i32 %22, -10000
%24 = icmp ult i32 %23, -9999
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
tail call void @exit(i32 0)
unreachable
27: ; preds = %16
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i32 %22)
%29 = call i32 (i8*, ...) bitcast (i32 (...)* @write_gridfile to i32 (i8*, ...)*)(i8* %4)
%30 = call i32 (i8*, ...) bitcast (i32 (...)* @print_header to i32 (i8*, ...)*)(i8* %4)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i32 1)
%32 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_gridinfo to i32 (i8*, i32, ...)*)(i8* %4, i32 1)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i32 2)
%34 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_gridinfo to i32 (i8*, i32, ...)*)(i8* %4, i32 2)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i32 3)
%36 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_gridinfo to i32 (i8*, i32, ...)*)(i8* %4, i32 3)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i32 4)
%38 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @print_gridinfo to i32 (i8*, i32, ...)*)(i8* %4, i32 4)
ret i32 0
}