#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*/ SEEK_END;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ closeCommIEEE();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ identify2034();
int /*<<< orphan*/ init2034(int /*<<< orphan*/, int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readGPIB(char *, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ setBoardGPIB(int);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ *stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ writeGPIB(char *);
int /*<<< orphan*/ writenGPIB(char *, int);
int main(int argc, char **argv) {
  int primaryAddress = 3;
  int secondaryAddress = 0;
  char *storagefile = NULL;
  int i;
  int nbytes;
  char buffer[1001];
  char command[1001];
  char display_spec[1001];
  char measurement_spec[1001];
  char *data = NULL;
  FILE *filep = NULL;
  bool read = true;
  printf("\nTotal documentation of a B&K 2034 via GPIB\n\n");
  printf("Davide Bucci, 2015\n\n");
  if (argc > 1) {
    for (i = 1; i < argc; ++i) {
      if (strcmp(argv[i], "-h") == 0) {
        printf("This software communicates with a Bruel&Kjaer 2034 double "
               "channel FFT\n"
               "spectrum analyzer and records or sends back to the instrument "
               "its current\n"
               "state, which comprises the measurement settings, the data "
               "acquired as well\n"
               "as the visualization settings.\n"
               "\n"
               "\n"
               "The following options are available:\n"
               "\n"
               "   -h     Show this help\n"
               "\n"
               "   -b     Change the board interface index "
               "(GPIB0=0,GPIB1=1,etc.)\n"
               "\n"
               "   -p     Change the primary address of the BK 2034.\n"
               "\n"
               "   -s     Change the secondary address of the BK 2034.\n"
               "\n"
               "   -r     Record a total documentation of the BK 2034 on a "
               "given file.\n"
               "              (2034 -> file)\n"
               "\n"
               "   -t     Send back a total documentation to the BK 2034 from "
               "a given file.\n"
               "              (file -> 2034)\n"
               "\n\n");
        return 0;
      } else if (strcmp(argv[i], "-b") == 0) {
        if (argc > i + 1) {
          int wbi;
          sscanf(argv[++i], "%d", &wbi);
          if (wbi < 0 || wbi > 31) {
            fprintf(stderr, "Invalid board index (%d).\n", wbi);
          } else {
            setBoardGPIB(wbi);
          }
        } else {
          fprintf(stderr, "-b requires the board index.\n");
        }
      } else if (strcmp(argv[i], "-p") == 0) {
        if (argc > i + 1) {
          int wpa;
          sscanf(argv[++i], "%d", &wpa);
          if (wpa < 0 || wpa > 31) {
            fprintf(stderr, "Invalid address (%d).\n", wpa);
          } else {
            primaryAddress = wpa;
          }
        } else {
          fprintf(stderr, "-p requires the address.\n");
        }
      } else if (strcmp(argv[i], "-s") == 0) {
        if (argc > i + 1) {
          int wsa;
          sscanf(argv[++i], "%d", &wsa);
          if (wsa < 0 || wsa > 31) {
            fprintf(stderr, "Invalid address (%d).\n", wsa);
          } else {
            secondaryAddress = wsa;
          }
        } else {
          fprintf(stderr, "-s requires the address.\n");
        }
      } else if (strcmp(argv[i], "-r") == 0) {
        read = true;
        if (argc > i + 1) {
          storagefile = argv[++i];
        } else {
          fprintf(stderr, "-r requires the file name.\n");
        }
      } else if (strcmp(argv[i], "-t") == 0) {
        read = false;
        if (argc > i + 1) {
          storagefile = argv[++i];
        } else {
          fprintf(stderr, "-t requires the file name.\n");
        }
      }
    }
  }
  printf("Configuration settings:\n");
  printf("Primary address: %d, secondary: %d \n", primaryAddress,
         secondaryAddress);
  init2034(0, primaryAddress, secondaryAddress);
  identify2034();
  if (storagefile == NULL) {
    fprintf(stderr, "You should use -r or -t options to specify an "
                    "action, as well as a filename.\n");
    return 1;
  }
  if (read) {
    sprintf(command, "TOTAL_DOCUMENTATION\n");
    writeGPIB(command);
    readGPIB(buffer, 3);
    buffer[2] = '\0';
    if (strcmp(buffer, "TD") != 0) {
      fprintf(stderr,
              "TD has not been received from the instrument "
              "(%s).\n",
              buffer);
    }
    readGPIB(display_spec, 206);
    readGPIB(measurement_spec, 340);
    readGPIB(buffer, 2);
    buffer[2] = '\0';
    nbytes = buffer[0] + buffer[1] * 256;
    printf("Reading %d bytes from the B&K 2034.\n", nbytes);
    data = (char *)calloc(nbytes, 1);
    readGPIB(data, nbytes);
    filep = fopen(storagefile, "w");
    if (filep == NULL) {
      fprintf(stderr, "Could not open output file.\n");
      if (data != NULL)
        free(data);
      return 1;
    }
    fprintf(filep, "TD ");
    fwrite(display_spec, 206, 1, filep);
    fwrite(measurement_spec, 340, 1, filep);
    fwrite(buffer, 2, 1, filep);
    fwrite(data, nbytes, 1, filep);
    fprintf(filep, "\n");
    readGPIB(buffer, 1);
    fclose(filep);
    free(data);
    printf("File %s written\n", storagefile);
  } else {
    filep = fopen(storagefile, "r");
    if (filep == NULL) {
      fprintf(stderr, "Could not open input file.\n");
      return 1;
    }
    printf("Open file %s for read.\n", storagefile);
    int nbytes;
    fseek(filep, 0, SEEK_END);
    nbytes = ftell(filep);
    rewind(filep);
    char *filebuffer = (char *)malloc(sizeof(char) * nbytes);
    if (filebuffer == NULL) {
      fprintf(stderr, "Could not allocate enough memory to read the "
                      "input file.\n");
      return 2;
    }
    int result = fread(filebuffer, 1, nbytes, filep);
    if (result != nbytes) {
      fprintf(stderr, "Could not read correctly the input file.\n");
      return 3;
    }
    writenGPIB(filebuffer, nbytes);
    fclose(filep);
  }
  closeCommIEEE();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0xff8(%rbp)
movq   $0x0,-0x1000(%rbp)
movl   $0x1,-0x1004(%rbp)
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    168b <main+0x42b>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1686 <main+0x426>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd48(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    1324 <main+0xc4>
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1a94 <main+0x834>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xfcd(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    13e8 <main+0x188>
mov    -0x8(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    13cb <main+0x16b>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xf95(%rip),%rsi
lea    -0x1008(%rbp),%rdx
call   1120 <sscanf@plt>
cmpl   $0x0,-0x1008(%rbp)
jl     1398 <main+0x138>
cmpl   $0x1f,-0x1008(%rbp)
jle    13bb <main+0x15b>
mov    0x2c39(%rip),%rax
mov    (%rax),%rdi
mov    -0x1008(%rbp),%edx
lea    0xf5b(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
jmp    13c6 <main+0x166>
mov    -0x1008(%rbp),%edi
call   1110 <setBoardGPIB@plt>
jmp    13e3 <main+0x183>
mov    0x2c06(%rip),%rax
mov    (%rax),%rdi
lea    0xf49(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
jmp    166e <main+0x40e>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xf48(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    14aa <main+0x24a>
mov    -0x8(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    148d <main+0x22d>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xed1(%rip),%rsi
lea    -0x100c(%rbp),%rdx
call   1120 <sscanf@plt>
cmpl   $0x0,-0x100c(%rbp)
jl     145c <main+0x1fc>
cmpl   $0x1f,-0x100c(%rbp)
jle    147f <main+0x21f>
mov    0x2b75(%rip),%rax
mov    (%rax),%rdi
mov    -0x100c(%rbp),%edx
lea    0xed3(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
jmp    1488 <main+0x228>
mov    -0x100c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    14a5 <main+0x245>
mov    0x2b44(%rip),%rax
mov    (%rax),%rdi
lea    0xebf(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
jmp    1669 <main+0x409>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xeba(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    156c <main+0x30c>
mov    -0x8(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    154f <main+0x2ef>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe0f(%rip),%rsi
lea    -0x1010(%rbp),%rdx
call   1120 <sscanf@plt>
cmpl   $0x0,-0x1010(%rbp)
jl     151e <main+0x2be>
cmpl   $0x1f,-0x1010(%rbp)
jle    1541 <main+0x2e1>
mov    0x2ab3(%rip),%rax
mov    (%rax),%rdi
mov    -0x1010(%rbp),%edx
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
jmp    154a <main+0x2ea>
mov    -0x1010(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1567 <main+0x307>
mov    0x2a82(%rip),%rax
mov    (%rax),%rdi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
jmp    1664 <main+0x404>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe15(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    15e3 <main+0x383>
movl   $0x1,-0x1004(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    15c6 <main+0x366>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
jmp    15de <main+0x37e>
mov    0x2a0b(%rip),%rax
mov    (%rax),%rdi
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
jmp    165f <main+0x3ff>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdbd(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    165a <main+0x3fa>
movl   $0x0,-0x1004(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    163d <main+0x3dd>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
jmp    1655 <main+0x3f5>
mov    0x2994(%rip),%rax
mov    (%rax),%rdi
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
jmp    165a <main+0x3fa>
jmp    165f <main+0x3ff>
jmp    1664 <main+0x404>
jmp    1669 <main+0x409>
jmp    166e <main+0x40e>
jmp    1673 <main+0x413>
jmp    1678 <main+0x418>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12dc <main+0x7c>
jmp    168b <main+0x42b>
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
xor    %edi,%edi
call   1050 <init2034@plt>
mov    $0x0,%al
call   1130 <identify2034@plt>
cmpq   $0x0,-0x20(%rbp)
jne    16f0 <main+0x490>
mov    0x2905(%rip),%rax
mov    (%rax),%rdi
lea    0xd33(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a94 <main+0x834>
cmpl   $0x0,-0x1004(%rbp)
je     1933 <main+0x6d3>
lea    -0x810(%rbp),%rdi
lea    0xd53(%rip),%rsi
call   1170 <sprintf@plt>
lea    -0x810(%rbp),%rdi
call   1150 <writeGPIB@plt>
lea    -0x420(%rbp),%rdi
mov    $0x3,%esi
call   10b0 <readGPIB@plt>
movb   $0x0,-0x41e(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xd31(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
je     1770 <main+0x510>
mov    0x2880(%rip),%rax
mov    (%rax),%rdi
lea    -0x420(%rbp),%rdx
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
lea    -0xc00(%rbp),%rdi
mov    $0xce,%esi
call   10b0 <readGPIB@plt>
lea    -0xff0(%rbp),%rdi
mov    $0x154,%esi
call   10b0 <readGPIB@plt>
lea    -0x420(%rbp),%rdi
mov    $0x2,%esi
call   10b0 <readGPIB@plt>
movb   $0x0,-0x41e(%rbp)
movsbl -0x420(%rbp),%eax
movsbl -0x41f(%rbp),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xce0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%edi
mov    $0x1,%esi
call   10c0 <calloc@plt>
mov    %rax,-0xff8(%rbp)
mov    -0xff8(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   10b0 <readGPIB@plt>
mov    -0x20(%rbp),%rdi
lea    0xcd0(%rip),%rsi
call   1160 <fopen@plt>
mov    %rax,-0x1000(%rbp)
cmpq   $0x0,-0x1000(%rbp)
jne    1857 <main+0x5f7>
mov    0x27b8(%rip),%rax
mov    (%rax),%rdi
lea    0xca7(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
cmpq   $0x0,-0xff8(%rbp)
je     184b <main+0x5eb>
mov    -0xff8(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a94 <main+0x834>
mov    -0x1000(%rbp),%rdi
lea    0xc89(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
lea    -0xc00(%rbp),%rdi
mov    -0x1000(%rbp),%rcx
mov    $0xce,%esi
mov    $0x1,%edx
call   1180 <fwrite@plt>
lea    -0xff0(%rbp),%rdi
mov    -0x1000(%rbp),%rcx
mov    $0x154,%esi
mov    $0x1,%edx
call   1180 <fwrite@plt>
lea    -0x420(%rbp),%rdi
mov    -0x1000(%rbp),%rcx
mov    $0x2,%esi
mov    $0x1,%edx
call   1180 <fwrite@plt>
mov    -0xff8(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x1000(%rbp),%rcx
mov    $0x1,%edx
call   1180 <fwrite@plt>
mov    -0x1000(%rbp),%rdi
lea    0xa16(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
lea    -0x420(%rbp),%rdi
mov    $0x1,%esi
call   10b0 <readGPIB@plt>
mov    -0x1000(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0xff8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rsi
lea    0xbcb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1a86 <main+0x826>
mov    -0x20(%rbp),%rdi
lea    0xa57(%rip),%rsi
call   1160 <fopen@plt>
mov    %rax,-0x1000(%rbp)
cmpq   $0x0,-0x1000(%rbp)
jne    197c <main+0x71c>
mov    0x2679(%rip),%rax
mov    (%rax),%rdi
lea    0xb9a(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a94 <main+0x834>
mov    -0x20(%rbp),%rsi
lea    0xb98(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x1000(%rbp),%rdi
mov    0x264c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1140 <fseek@plt>
mov    -0x1000(%rbp),%rdi
call   10f0 <ftell@plt>
mov    %eax,-0x1014(%rbp)
mov    -0x1000(%rbp),%rdi
call   1080 <rewind@plt>
movslq -0x1014(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1100 <malloc@plt>
mov    %rax,-0x1020(%rbp)
cmpq   $0x0,-0x1020(%rbp)
jne    1a0e <main+0x7ae>
mov    0x25e7(%rip),%rax
mov    (%rax),%rdi
lea    0xb3c(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1a94 <main+0x834>
mov    -0x1020(%rbp),%rdi
mov    -0x1014(%rbp),%edx
mov    -0x1000(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x1024(%rbp)
mov    -0x1024(%rbp),%eax
cmp    -0x1014(%rbp),%eax
je     1a68 <main+0x808>
mov    0x258d(%rip),%rax
mov    (%rax),%rdi
lea    0xb1c(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    1a94 <main+0x834>
mov    -0x1020(%rbp),%rdi
mov    -0x1014(%rbp),%esi
call   1090 <writenGPIB@plt>
mov    -0x1000(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x0,%al
call   10a0 <closeCommIEEE@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfe8,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0x1003(%rip),%rdi
call   1040 <puts@plt>
lea    0x1024(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%r14d
jl     1563 <main+0x303>
movl   $0x1,0xc(%rsp)
movl   $0x3,0x14(%rsp)
lea    0xd50(%rip),%r13
movl   $0x0,0x10(%rsp)
xor    %eax,%eax
mov    %rax,0x18(%rsp)
mov    $0x1,%r15d
jmp    12fa <main+0x9a>
mov    0x2d0a(%rip),%rax
mov    (%rax),%rcx
mov    $0x1d,%esi
mov    $0x1,%edx
lea    0xd42(%rip),%rdi
call   1180 <fwrite@plt>
mov    %r15d,%r12d
add    $0x1,%r12d
mov    %r12d,%r15d
cmp    %r14d,%r12d
jge    1582 <main+0x322>
movslq %r15d,%rbp
mov    (%rbx,%rbp,8),%rdi
mov    %r13,%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     17d1 <main+0x571>
mov    (%rbx,%rbp,8),%rdi
lea    0xce6(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     13c0 <main+0x160>
mov    (%rbx,%rbp,8),%rdi
lea    0xd0c(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     1410 <main+0x1b0>
mov    (%rbx,%rbp,8),%rdi
lea    0xd27(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     1443 <main+0x1e3>
mov    (%rbx,%rbp,8),%rdi
lea    0xd2b(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     14be <main+0x25e>
mov    (%rbx,%rbp,8),%rdi
lea    0xd31(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
jne    12e7 <main+0x87>
lea    0x1(%r15),%r12d
cmp    %r14d,%r12d
jge    1536 <main+0x2d6>
movslq %r12d,%rax
mov    (%rbx,%rax,8),%rax
mov    %rax,0x18(%rsp)
movl   $0x0,0xc(%rsp)
jmp    12ea <main+0x8a>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%r15),%r12d
cmp    %r14d,%r12d
jge    12c7 <main+0x67>
movslq %r12d,%rax
mov    (%rbx,%rax,8),%rdi
lea    0xc2b(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1130 <sscanf@plt>
mov    0x20(%rsp),%edx
cmp    $0x20,%edx
jb     14b2 <main+0x252>
mov    0x2bdf(%rip),%rax
mov    (%rax),%rdi
lea    0xc06(%rip),%rsi
jmp    1486 <main+0x226>
nopl   0x0(%rax,%rax,1)
lea    0x1(%r15),%r12d
cmp    %r14d,%r12d
jge    1492 <main+0x232>
movslq %r12d,%rax
mov    (%rbx,%rax,8),%rdi
lea    0xbdf(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1130 <sscanf@plt>
mov    0x20(%rsp),%edx
cmp    $0x20,%edx
jae    1475 <main+0x215>
mov    %edx,0x14(%rsp)
jmp    12ea <main+0x8a>
lea    0x1(%r15),%r12d
cmp    %r14d,%r12d
jge    14e0 <main+0x280>
movslq %r12d,%rax
mov    (%rbx,%rax,8),%rdi
lea    0xba8(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1130 <sscanf@plt>
mov    0x20(%rsp),%edx
cmp    $0x20,%edx
jb     152d <main+0x2cd>
mov    0x2b5c(%rip),%rax
mov    (%rax),%rdi
lea    0xbbf(%rip),%rsi
xor    %eax,%eax
call   10f0 <fprintf@plt>
jmp    12ea <main+0x8a>
mov    0x2b3f(%rip),%rax
mov    (%rax),%rcx
mov    $0x19,%esi
mov    $0x1,%edx
lea    0xbaf(%rip),%rdi
jmp    12e2 <main+0x82>
mov    %edx,%edi
call   1120 <setBoardGPIB@plt>
jmp    12ea <main+0x8a>
lea    0x1(%r15),%r12d
cmp    %r14d,%r12d
jge    1500 <main+0x2a0>
movslq %r12d,%rax
mov    (%rbx,%rax,8),%rax
mov    %rax,0x18(%rsp)
movl   $0x1,0xc(%rsp)
jmp    12ea <main+0x8a>
mov    0x2af1(%rip),%rax
mov    (%rax),%rcx
mov    $0x19,%esi
mov    $0x1,%edx
lea    0xb7e(%rip),%rdi
jmp    12e2 <main+0x82>
mov    0x2ad1(%rip),%rax
mov    (%rax),%rcx
mov    $0x1b,%esi
mov    $0x1,%edx
lea    0xb7b(%rip),%rdi
call   1180 <fwrite@plt>
movl   $0x1,0xc(%rsp)
jmp    12e7 <main+0x87>
mov    %edx,0x10(%rsp)
jmp    12ea <main+0x8a>
mov    0x2a9b(%rip),%rax
mov    (%rax),%rcx
mov    $0x1b,%esi
mov    $0x1,%edx
lea    0xb64(%rip),%rdi
call   1180 <fwrite@plt>
movl   $0x0,0xc(%rsp)
jmp    12e7 <main+0x87>
movl   $0x3,0x14(%rsp)
xor    %eax,%eax
mov    %rax,0x18(%rsp)
movl   $0x1,0xc(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xd39(%rip),%rdi
call   1040 <puts@plt>
lea    0xb3c(%rip),%rdi
mov    0x14(%rsp),%ebx
mov    %ebx,%esi
mov    0x10(%rsp),%ebp
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
mov    %ebx,%esi
mov    %ebp,%edx
call   1060 <init2034@plt>
xor    %eax,%eax
call   1140 <identify2034@plt>
mov    0x18(%rsp),%r12
test   %r12,%r12
je     17a7 <main+0x547>
cmpl   $0x0,0xc(%rsp)
je     17e4 <main+0x584>
movups 0xb6a(%rip),%xmm0
movaps %xmm0,0x410(%rsp)
movabs $0xa4e4f49544154,%rax
mov    %rax,0x41d(%rsp)
lea    0x410(%rsp),%rdi
call   1160 <writeGPIB@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%esi
call   10c0 <readGPIB@plt>
movb   $0x0,0x22(%rsp)
lea    0xb3a(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     1649 <main+0x3e9>
mov    0x29a5(%rip),%rax
mov    (%rax),%rdi
lea    0xb1f(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   10f0 <fprintf@plt>
lea    0xbf0(%rsp),%rdi
mov    $0xce,%esi
call   10c0 <readGPIB@plt>
lea    0x800(%rsp),%rdi
mov    $0x154,%esi
call   10c0 <readGPIB@plt>
lea    0x20(%rsp),%rdi
mov    $0x2,%esi
call   10c0 <readGPIB@plt>
movb   $0x0,0x22(%rsp)
movsbl 0x20(%rsp),%eax
movsbl 0x21(%rsp),%ebp
shl    $0x8,%ebp
add    %eax,%ebp
lea    0xaf9(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%ebx
mov    %ebp,%edi
mov    $0x1,%esi
call   10d0 <calloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebp,%esi
call   10c0 <readGPIB@plt>
lea    0xaf0(%rip),%rsi
mov    %r12,%rdi
call   1170 <fopen@plt>
test   %rax,%rax
je     187e <main+0x61e>
mov    %rax,%r15
lea    0xaf4(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1180 <fwrite@plt>
lea    0xbf0(%rsp),%rdi
mov    $0xce,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1180 <fwrite@plt>
lea    0x800(%rsp),%rdi
mov    $0x154,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1180 <fwrite@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1180 <fwrite@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1180 <fwrite@plt>
lea    0xe3c(%rip),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1180 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   10c0 <readGPIB@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xa49(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   10b0 <closeCommIEEE@plt>
jmp    1914 <main+0x6b4>
mov    0x282a(%rip),%rax
mov    (%rax),%rcx
lea    0x93e(%rip),%rdi
mov    $0x4d,%esi
mov    $0x1,%edx
call   1180 <fwrite@plt>
mov    $0x1,%ebx
jmp    1914 <main+0x6b4>
lea    0xb02(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    1914 <main+0x6b4>
lea    0x8a9(%rip),%rsi
mov    %r12,%rdi
call   1170 <fopen@plt>
test   %rax,%rax
je     18ad <main+0x64d>
mov    %rax,%rbx
lea    0x9ff(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x27d1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1150 <fseek@plt>
mov    %rbx,%rdi
call   1100 <ftell@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1090 <rewind@plt>
mov    %r14d,%edi
call   1110 <malloc@plt>
test   %rax,%rax
je     18c8 <main+0x668>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    %r14d,%eax
jne    18ef <main+0x68f>
mov    %rbp,%rdi
mov    %r14d,%esi
call   10a0 <writenGPIB@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
jmp    1799 <main+0x539>
mov    0x2753(%rip),%rax
mov    (%rax),%rcx
lea    0x928(%rip),%rdi
mov    $0x1c,%esi
mov    $0x1,%edx
call   1180 <fwrite@plt>
test   %r14,%r14
je     1914 <main+0x6b4>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1914 <main+0x6b4>
mov    0x2724(%rip),%rax
mov    (%rax),%rcx
lea    0x92b(%rip),%rdi
mov    $0x1b,%esi
jmp    17bd <main+0x55d>
mov    0x2709(%rip),%rax
mov    (%rax),%rcx
lea    0x944(%rip),%rdi
mov    $0x39,%esi
mov    $0x1,%edx
call   1180 <fwrite@plt>
mov    $0x2,%ebx
jmp    1914 <main+0x6b4>
mov    0x26e2(%rip),%rax
mov    (%rax),%rcx
lea    0x957(%rip),%rdi
mov    $0x29,%esi
mov    $0x1,%edx
call   1180 <fwrite@plt>
mov    $0x3,%ebx
mov    %ebx,%eax
add    $0xfe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"\0ATotal documentation of a B&K 2034 via GPIB\0A\0A\00"
@.str.1 = [21 x i8] c"Davide Bucci, 2015\0A\0A\00"
@.str.2 = [3 x i8] c"-h\00"
@.str.3 = [702 x i8] c"This software communicates with a Bruel&Kjaer 2034 double channel FFT\0Aspectrum analyzer and records or sends back to the instrument its current\0Astate, which comprises the measurement settings, the data acquired as well\0Aas the visualization settings.\0A\0A\0AThe following options are available:\0A\0A -h Show this help\0A\0A -b Change the board interface index (GPIB0=0,GPIB1=1,etc.)\0A\0A -p Change the primary address of the BK 2034.\0A\0A -s Change the secondary address of the BK 2034.\0A\0A -r Record a total documentation of the BK 2034 on a given file.\0A (2034 -> file)\0A\0A -t Send back a total documentation to the BK 2034 from a given file.\0A (file -> 2034)\0A\0A\0A\00"
@.str.4 = [3 x i8] c"-b\00"
@.str.5 = [3 x i8] c"%d\00"
@stderr = global i32* null
@.str.6 = [27 x i8] c"Invalid board index (%d).\0A\00"
@.str.7 = [30 x i8] c"-b requires the board index.\0A\00"
@.str.8 = [3 x i8] c"-p\00"
@.str.9 = [23 x i8] c"Invalid address (%d).\0A\00"
@.str.10 = [26 x i8] c"-p requires the address.\0A\00"
@.str.11 = [3 x i8] c"-s\00"
@.str.12 = [26 x i8] c"-s requires the address.\0A\00"
@.str.13 = [3 x i8] c"-r\00"
@.str.14 = [28 x i8] c"-r requires the file name.\0A\00"
@.str.15 = [3 x i8] c"-t\00"
@.str.16 = [28 x i8] c"-t requires the file name.\0A\00"
@.str.17 = [25 x i8] c"Configuration settings:\0A\00"
@.str.18 = [37 x i8] c"Primary address: %d, secondary: %d \0A\00"
@.str.19 = [78 x i8] c"You should use -r or -t options to specify an action, as well as a filename.\0A\00"
@.str.20 = [21 x i8] c"TOTAL_DOCUMENTATION\0A\00"
@.str.21 = [3 x i8] c"TD\00"
@.str.22 = [52 x i8] c"TD has not been received from the instrument (%s).\0A\00"
@.str.23 = [37 x i8] c"Reading %d bytes from the B&K 2034.\0A\00"
@.str.24 = [2 x i8] c"w\00"
@.str.25 = [29 x i8] c"Could not open output file.\0A\00"
@.str.26 = [4 x i8] c"TD \00"
@.str.27 = [2 x i8] c"\0A\00"
@.str.28 = [17 x i8] c"File %s written\0A\00"
@.str.29 = [2 x i8] c"r\00"
@.str.30 = [28 x i8] c"Could not open input file.\0A\00"
@.str.31 = [24 x i8] c"Open file %s for read.\0A\00"
@SEEK_END = global i32 0
@.str.32 = [58 x i8] c"Could not allocate enough memory to read the input file.\0A\00"
@.str.33 = [42 x i8] c"Could not read correctly the input file.\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 i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1001 x i8]
%12 = alloca [1001 x i8]
%13 = alloca [1001 x i8]
%14 = alloca [1001 x i8]
%15 = alloca i8*
%16 = alloca i32*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i8*
%23 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 3, i32* %6
store i32 0, i32* %7
store i8* null, i8** %8
store i8* null, i8** %15
store i32* null, i32** %16
store i32 1, i32* %17
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 1
br i1 %27, label %28, label %213
28: ; preds = %2
store i32 1, i32* %9
br label %29
29: ; preds = %209, %28
%30 = load i32, i32* %9
%31 = load i32, i32* %4
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %212
33: ; preds = %29
%34 = load i8**, i8*** %5
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %33
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([702 x i8], [702 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %356
43: ; preds = %33
%44 = load i8**, i8*** %5
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %81
51: ; preds = %43
%52 = load i32, i32* %4
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
%55 = icmp sgt i32 %52, %54
br i1 %55, label %56, label %77
56: ; preds = %51
%57 = load i8**, i8*** %5
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %57, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 @sscanf(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %18)
%64 = load i32, i32* %18
%65 = icmp slt i32 %64, 0
br i1 %65, label %69, label %66
66: ; preds = %56
%67 = load i32, i32* %18
%68 = icmp sgt i32 %67, 31
br i1 %68, label %69, label %73
69: ; preds = %66, %56
%70 = load i32*, i32** @stderr
%71 = load i32, i32* %18
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %71)
br label %76
73: ; preds = %66
%74 = load i32, i32* %18
%75 = call i32 @setBoardGPIB(i32 %74)
br label %76
76: ; preds = %73, %69
br label %80
77: ; preds = %51
%78 = load i32*, i32** @stderr
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %78, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
br label %80
80: ; preds = %77, %76
br label %207
81: ; preds = %43
%82 = load i8**, i8*** %5
%83 = load i32, i32* %9
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %82, i64 %84
%86 = load i8*, i8** %85
%87 = call i64 @strcmp(i8* %86, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %118
89: ; preds = %81
%90 = load i32, i32* %4
%91 = load i32, i32* %9
%92 = add nsw i32 %91, 1
%93 = icmp sgt i32 %90, %92
br i1 %93, label %94, label %114
94: ; preds = %89
%95 = load i8**, i8*** %5
%96 = load i32, i32* %9
%97 = add nsw i32 %96, 1
store i32 %97, i32* %9
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8*, i8** %95, i64 %98
%100 = load i8*, i8** %99
%101 = call i32 @sscanf(i8* %100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %19)
%102 = load i32, i32* %19
%103 = icmp slt i32 %102, 0
br i1 %103, label %107, label %104
104: ; preds = %94
%105 = load i32, i32* %19
%106 = icmp sgt i32 %105, 31
br i1 %106, label %107, label %111
107: ; preds = %104, %94
%108 = load i32*, i32** @stderr
%109 = load i32, i32* %19
%110 = call i32 (i32*, i8*, ...) @fprintf(i32* %108, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i32 %109)
br label %113
111: ; preds = %104
%112 = load i32, i32* %19
store i32 %112, i32* %6
br label %113
113: ; preds = %111, %107
br label %117
114: ; preds = %89
%115 = load i32*, i32** @stderr
%116 = call i32 (i32*, i8*, ...) @fprintf(i32* %115, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
br label %117
117: ; preds = %114, %113
br label %206
118: ; preds = %81
%119 = load i8**, i8*** %5
%120 = load i32, i32* %9
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i8*, i8** %119, i64 %121
%123 = load i8*, i8** %122
%124 = call i64 @strcmp(i8* %123, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%125 = icmp eq i64 %124, 0
br i1 %125, label %126, label %155
126: ; preds = %118
%127 = load i32, i32* %4
%128 = load i32, i32* %9
%129 = add nsw i32 %128, 1
%130 = icmp sgt i32 %127, %129
br i1 %130, label %131, label %151
131: ; preds = %126
%132 = load i8**, i8*** %5
%133 = load i32, i32* %9
%134 = add nsw i32 %133, 1
store i32 %134, i32* %9
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds i8*, i8** %132, i64 %135
%137 = load i8*, i8** %136
%138 = call i32 @sscanf(i8* %137, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %20)
%139 = load i32, i32* %20
%140 = icmp slt i32 %139, 0
br i1 %140, label %144, label %141
141: ; preds = %131
%142 = load i32, i32* %20
%143 = icmp sgt i32 %142, 31
br i1 %143, label %144, label %148
144: ; preds = %141, %131
%145 = load i32*, i32** @stderr
%146 = load i32, i32* %20
%147 = call i32 (i32*, i8*, ...) @fprintf(i32* %145, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i32 %146)
br label %150
148: ; preds = %141
%149 = load i32, i32* %20
store i32 %149, i32* %7
br label %150
150: ; preds = %148, %144
br label %154
151: ; preds = %126
%152 = load i32*, i32** @stderr
%153 = call i32 (i32*, i8*, ...) @fprintf(i32* %152, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0))
br label %154
154: ; preds = %151, %150
br label %205
155: ; preds = %118
%156 = load i8**, i8*** %5
%157 = load i32, i32* %9
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i8*, i8** %156, i64 %158
%160 = load i8*, i8** %159
%161 = call i64 @strcmp(i8* %160, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
%162 = icmp eq i64 %161, 0
br i1 %162, label %163, label %179
163: ; preds = %155
store i32 1, i32* %17
%164 = load i32, i32* %4
%165 = load i32, i32* %9
%166 = add nsw i32 %165, 1
%167 = icmp sgt i32 %164, %166
br i1 %167, label %168, label %175
168: ; preds = %163
%169 = load i8**, i8*** %5
%170 = load i32, i32* %9
%171 = add nsw i32 %170, 1
store i32 %171, i32* %9
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds i8*, i8** %169, i64 %172
%174 = load i8*, i8** %173
store i8* %174, i8** %8
br label %178
175: ; preds = %163
%176 = load i32*, i32** @stderr
%177 = call i32 (i32*, i8*, ...) @fprintf(i32* %176, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.14, i64 0, i64 0))
br label %178
178: ; preds = %175, %168
br label %204
179: ; preds = %155
%180 = load i8**, i8*** %5
%181 = load i32, i32* %9
%182 = sext i32 %181 to i64
%183 = getelementptr inbounds i8*, i8** %180, i64 %182
%184 = load i8*, i8** %183
%185 = call i64 @strcmp(i8* %184, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0))
%186 = icmp eq i64 %185, 0
br i1 %186, label %187, label %203
187: ; preds = %179
store i32 0, i32* %17
%188 = load i32, i32* %4
%189 = load i32, i32* %9
%190 = add nsw i32 %189, 1
%191 = icmp sgt i32 %188, %190
br i1 %191, label %192, label %199
192: ; preds = %187
%193 = load i8**, i8*** %5
%194 = load i32, i32* %9
%195 = add nsw i32 %194, 1
store i32 %195, i32* %9
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds i8*, i8** %193, i64 %196
%198 = load i8*, i8** %197
store i8* %198, i8** %8
br label %202
199: ; preds = %187
%200 = load i32*, i32** @stderr
%201 = call i32 (i32*, i8*, ...) @fprintf(i32* %200, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.16, i64 0, i64 0))
br label %202
202: ; preds = %199, %192
br label %203
203: ; preds = %202, %179
br label %204
204: ; preds = %203, %178
br label %205
205: ; preds = %204, %154
br label %206
206: ; preds = %205, %117
br label %207
207: ; preds = %206, %80
br label %208
208: ; preds = %207
br label %209
209: ; preds = %208
%210 = load i32, i32* %9
%211 = add nsw i32 %210, 1
store i32 %211, i32* %9
br label %29
212: ; preds = %29
br label %213
213: ; preds = %212, %2
%214 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.17, i64 0, i64 0))
%215 = load i32, i32* %6
%216 = load i32, i32* %7
%217 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.18, i64 0, i64 0), i32 %215, i32 %216)
%218 = load i32, i32* %6
%219 = load i32, i32* %7
%220 = call i32 @init2034(i32 0, i32 %218, i32 %219)
%221 = call i32 (...) @identify2034()
%222 = load i8*, i8** %8
%223 = icmp eq i8* %222, null
br i1 %223, label %224, label %227
224: ; preds = %213
%225 = load i32*, i32** @stderr
%226 = call i32 (i32*, i8*, ...) @fprintf(i32* %225, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.19, i64 0, i64 0))
store i32 1, i32* %3
br label %356
227: ; preds = %213
%228 = load i32, i32* %17
%229 = icmp ne i32 %228, 0
br i1 %229, label %230, label %308
230: ; preds = %227
%231 = getelementptr inbounds [1001 x i8], [1001 x i8]* %12, i64 0, i64 0
%232 = call i32 @sprintf(i8* %231, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.20, i64 0, i64 0))
%233 = getelementptr inbounds [1001 x i8], [1001 x i8]* %12, i64 0, i64 0
%234 = call i32 @writeGPIB(i8* %233)
%235 = getelementptr inbounds [1001 x i8], [1001 x i8]* %11, i64 0, i64 0
%236 = call i32 @readGPIB(i8* %235, i32 3)
%237 = getelementptr inbounds [1001 x i8], [1001 x i8]* %11, i64 0, i64 2
store i8 0, i8* %237
%238 = getelementptr inbounds [1001 x i8], [1001 x i8]* %11, i64 0, i64 0
%239 = call i64 @strcmp(i8* %238, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.21, i64 0, i64 0))
%240 = icmp ne i64 %239, 0
br i1 %240, label %241, label %245
241: ; preds = %230
%242 = load i32*, i32** @stderr
%243 = getelementptr inbounds [1001 x i8], [1001 x i8]* %11, i64 0, i64 0
%244 = call i32 (i32*, i8*, ...) @fprintf(i32* %242, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.22, i64 0, i64 0), i8* %243)
br label %245
245: ; preds = %241, %230
%246 = getelementptr inbounds [1001 x i8], [1001 x i8]* %13, i64 0, i64 0
%247 = call i32 @readGPIB(i8* %246, i32 206)
%248 = getelementptr inbounds [1001 x i8], [1001 x i8]* %14, i64 0, i64 0
%249 = call i32 @readGPIB(i8* %248, i32 340)
%250 = getelementptr inbounds [1001 x i8], [1001 x i8]* %11, i64 0, i64 0
%251 = call i32 @readGPIB(i8* %250, i32 2)
%252 = getelementptr inbounds [1001 x i8], [1001 x i8]* %11, i64 0, i64 2
store i8 0, i8* %252
%253 = getelementptr inbounds [1001 x i8], [1001 x i8]* %11, i64 0, i64 0
%254 = load i8, i8* %253
%255 = sext i8 %254 to i32
%256 = getelementptr inbounds [1001 x i8], [1001 x i8]* %11, i64 0, i64 1
%257 = load i8, i8* %256
%258 = sext i8 %257 to i32
%259 = mul nsw i32 %258, 256
%260 = add nsw i32 %255, %259
store i32 %260, i32* %10
%261 = load i32, i32* %10
%262 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.23, i64 0, i64 0), i32 %261)
%263 = load i32, i32* %10
%264 = call i64 @calloc(i32 %263, i32 1)
%265 = inttoptr i64 %264 to i8*
store i8* %265, i8** %15
%266 = load i8*, i8** %15
%267 = load i32, i32* %10
%268 = call i32 @readGPIB(i8* %266, i32 %267)
%269 = load i8*, i8** %8
%270 = call i32* @fopen(i8* %269, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.24, i64 0, i64 0))
store i32* %270, i32** %16
%271 = load i32*, i32** %16
%272 = icmp eq i32* %271, null
br i1 %272, label %273, label %282
273: ; preds = %245
%274 = load i32*, i32** @stderr
%275 = call i32 (i32*, i8*, ...) @fprintf(i32* %274, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.25, i64 0, i64 0))
%276 = load i8*, i8** %15
%277 = icmp ne i8* %276, null
br i1 %277, label %278, label %281
278: ; preds = %273
%279 = load i8*, i8** %15
%280 = call i32 @free(i8* %279)
br label %281
281: ; preds = %278, %273
store i32 1, i32* %3
br label %356
282: ; preds = %245
%283 = load i32*, i32** %16
%284 = call i32 (i32*, i8*, ...) @fprintf(i32* %283, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.26, i64 0, i64 0))
%285 = getelementptr inbounds [1001 x i8], [1001 x i8]* %13, i64 0, i64 0
%286 = load i32*, i32** %16
%287 = call i32 @fwrite(i8* %285, i32 206, i32 1, i32* %286)
%288 = getelementptr inbounds [1001 x i8], [1001 x i8]* %14, i64 0, i64 0
%289 = load i32*, i32** %16
%290 = call i32 @fwrite(i8* %288, i32 340, i32 1, i32* %289)
%291 = getelementptr inbounds [1001 x i8], [1001 x i8]* %11, i64 0, i64 0
%292 = load i32*, i32** %16
%293 = call i32 @fwrite(i8* %291, i32 2, i32 1, i32* %292)
%294 = load i8*, i8** %15
%295 = load i32, i32* %10
%296 = load i32*, i32** %16
%297 = call i32 @fwrite(i8* %294, i32 %295, i32 1, i32* %296)
%298 = load i32*, i32** %16
%299 = call i32 (i32*, i8*, ...) @fprintf(i32* %298, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.27, i64 0, i64 0))
%300 = getelementptr inbounds [1001 x i8], [1001 x i8]* %11, i64 0, i64 0
%301 = call i32 @readGPIB(i8* %300, i32 1)
%302 = load i32*, i32** %16
%303 = call i32 @fclose(i32* %302)
%304 = load i8*, i8** %15
%305 = call i32 @free(i8* %304)
%306 = load i8*, i8** %8
%307 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.28, i64 0, i64 0), i8* %306)
br label %354
308: ; preds = %227
%309 = load i8*, i8** %8
%310 = call i32* @fopen(i8* %309, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.29, i64 0, i64 0))
store i32* %310, i32** %16
%311 = load i32*, i32** %16
%312 = icmp eq i32* %311, null
br i1 %312, label %313, label %316
313: ; preds = %308
%314 = load i32*, i32** @stderr
%315 = call i32 (i32*, i8*, ...) @fprintf(i32* %314, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.30, i64 0, i64 0))
store i32 1, i32* %3
br label %356
316: ; preds = %308
%317 = load i8*, i8** %8
%318 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.31, i64 0, i64 0), i8* %317)
%319 = load i32*, i32** %16
%320 = load i32, i32* @SEEK_END
%321 = call i32 @fseek(i32* %319, i32 0, i32 %320)
%322 = load i32*, i32** %16
%323 = call i32 @ftell(i32* %322)
store i32 %323, i32* %21
%324 = load i32*, i32** %16
%325 = call i32 @rewind(i32* %324)
%326 = load i32, i32* %21
%327 = sext i32 %326 to i64
%328 = mul i64 1, %327
%329 = trunc i64 %328 to i32
%330 = call i64 @malloc(i32 %329)
%331 = inttoptr i64 %330 to i8*
store i8* %331, i8** %22
%332 = load i8*, i8** %22
%333 = icmp eq i8* %332, null
br i1 %333, label %334, label %337
334: ; preds = %316
%335 = load i32*, i32** @stderr
%336 = call i32 (i32*, i8*, ...) @fprintf(i32* %335, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.32, i64 0, i64 0))
store i32 2, i32* %3
br label %356
337: ; preds = %316
%338 = load i8*, i8** %22
%339 = load i32, i32* %21
%340 = load i32*, i32** %16
%341 = call i32 @fread(i8* %338, i32 1, i32 %339, i32* %340)
store i32 %341, i32* %23
%342 = load i32, i32* %23
%343 = load i32, i32* %21
%344 = icmp ne i32 %342, %343
br i1 %344, label %345, label %348
345: ; preds = %337
%346 = load i32*, i32** @stderr
%347 = call i32 (i32*, i8*, ...) @fprintf(i32* %346, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.33, i64 0, i64 0))
store i32 3, i32* %3
br label %356
348: ; preds = %337
%349 = load i8*, i8** %22
%350 = load i32, i32* %21
%351 = call i32 @writenGPIB(i8* %349, i32 %350)
%352 = load i32*, i32** %16
%353 = call i32 @fclose(i32* %352)
br label %354
354: ; preds = %348, %282
%355 = call i32 (...) @closeCommIEEE()
store i32 0, i32* %3
br label %356
356: ; preds = %354, %345, %334, %313, %281, %224, %41
%357 = load i32, i32* %3
ret i32 %357
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"-h\00"
@.str.4 = [3 x i8] c"-b\00"
@.str.5 = [3 x i8] c"%d\00"
@stderr = global i32* null
@.str.6 = [27 x i8] c"Invalid board index (%d).\0A\00"
@.str.7 = [30 x i8] c"-b requires the board index.\0A\00"
@.str.8 = [3 x i8] c"-p\00"
@.str.9 = [23 x i8] c"Invalid address (%d).\0A\00"
@.str.10 = [26 x i8] c"-p requires the address.\0A\00"
@.str.11 = [3 x i8] c"-s\00"
@.str.12 = [26 x i8] c"-s requires the address.\0A\00"
@.str.13 = [3 x i8] c"-r\00"
@.str.14 = [28 x i8] c"-r requires the file name.\0A\00"
@.str.15 = [3 x i8] c"-t\00"
@.str.16 = [28 x i8] c"-t requires the file name.\0A\00"
@.str.18 = [37 x i8] c"Primary address: %d, secondary: %d \0A\00"
@.str.19 = [78 x i8] c"You should use -r or -t options to specify an action, as well as a filename.\0A\00"
@.str.20 = [21 x i8] c"TOTAL_DOCUMENTATION\0A\00"
@.str.21 = [3 x i8] c"TD\00"
@.str.22 = [52 x i8] c"TD has not been received from the instrument (%s).\0A\00"
@.str.23 = [37 x i8] c"Reading %d bytes from the B&K 2034.\0A\00"
@.str.24 = [2 x i8] c"w\00"
@.str.25 = [29 x i8] c"Could not open output file.\0A\00"
@.str.26 = [4 x i8] c"TD \00"
@.str.27 = [2 x i8] c"\0A\00"
@.str.28 = [17 x i8] c"File %s written\0A\00"
@.str.29 = [2 x i8] c"r\00"
@.str.30 = [28 x i8] c"Could not open input file.\0A\00"
@.str.31 = [24 x i8] c"Open file %s for read.\0A\00"
@SEEK_END = global i32 0
@.str.32 = [58 x i8] c"Could not allocate enough memory to read the input file.\0A\00"
@.str.33 = [42 x i8] c"Could not read correctly the input file.\0A\00"
@str = [45 x i8] c"\0ATotal documentation of a B&K 2034 via GPIB\0A\00"
@str.34 = [20 x i8] c"Davide Bucci, 2015\0A\00"
@str.35 = [24 x i8] c"Configuration settings:\00"
@str.36 = [701 x i8] c"This software communicates with a Bruel&Kjaer 2034 double channel FFT\0Aspectrum analyzer and records or sends back to the instrument its current\0Astate, which comprises the measurement settings, the data acquired as well\0Aas the visualization settings.\0A\0A\0AThe following options are available:\0A\0A -h Show this help\0A\0A -b Change the board interface index (GPIB0=0,GPIB1=1,etc.)\0A\0A -p Change the primary address of the BK 2034.\0A\0A -s Change the secondary address of the BK 2034.\0A\0A -r Record a total documentation of the BK 2034 on a given file.\0A (2034 -> file)\0A\0A -t Send back a total documentation to the BK 2034 from a given file.\0A (file -> 2034)\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1001 x i8]
%4 = alloca [1001 x i8]
%5 = alloca [1001 x i8]
%6 = alloca [1001 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = getelementptr inbounds [1001 x i8], [1001 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [1001 x i8], [1001 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [1001 x i8], [1001 x i8]* %6, i64 0, i64 0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.34, i64 0, i64 0))
%16 = icmp sgt i32 %0, 1
br i1 %16, label %17, label %137
17: ; preds = %2
%18 = bitcast i32* %9 to i8*
%19 = bitcast i32* %8 to i8*
%20 = bitcast i32* %7 to i8*
br label %21
21: ; preds = %17, %129
%22 = phi i32 [ 3, %17 ], [ %134, %129 ]
%23 = phi i32 [ 0, %17 ], [ %133, %129 ]
%24 = phi i32 [ 1, %17 ], [ %132, %129 ]
%25 = phi i8* [ null, %17 ], [ %131, %129 ]
%26 = phi i32 [ 1, %17 ], [ %135, %129 ]
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([701 x i8], [701 x i8]* @str.36, i64 0, i64 0))
br label %224
34: ; preds = %21
%35 = load i8*, i8** %28
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %57
38: ; preds = %34
%39 = add nsw i32 %26, 1
%40 = icmp slt i32 %39, %0
br i1 %40, label %41, label %54
41: ; preds = %38
%42 = sext i32 %39 to i64
%43 = getelementptr inbounds i8*, i8** %1, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @sscanf(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %7)
%46 = load i32, i32* %7
%47 = icmp ugt i32 %46, 31
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = load i32*, i32** @stderr
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %46)
br label %53
51: ; preds = %41
%52 = call i32 @setBoardGPIB(i32 %46)
br label %53
53: ; preds = %51, %48
br label %129
54: ; preds = %38
%55 = load i32*, i32** @stderr
%56 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i64 29, i64 1, i32* %55)
br label %129
57: ; preds = %34
%58 = load i8*, i8** %28
%59 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %79
61: ; preds = %57
%62 = add nsw i32 %26, 1
%63 = icmp slt i32 %62, %0
br i1 %63, label %64, label %76
64: ; preds = %61
%65 = sext i32 %62 to i64
%66 = getelementptr inbounds i8*, i8** %1, i64 %65
%67 = load i8*, i8** %66
%68 = call i32 @sscanf(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %8)
%69 = load i32, i32* %8
%70 = icmp ugt i32 %69, 31
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = load i32*, i32** @stderr
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i32 %69)
br label %74
74: ; preds = %64, %71
%75 = phi i32 [ %22, %71 ], [ %69, %64 ]
br label %129
76: ; preds = %61
%77 = load i32*, i32** @stderr
%78 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0), i64 25, i64 1, i32* %77)
br label %129
79: ; preds = %57
%80 = load i8*, i8** %28
%81 = call i64 @strcmp(i8* %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %101
83: ; preds = %79
%84 = add nsw i32 %26, 1
%85 = icmp slt i32 %84, %0
br i1 %85, label %86, label %98
86: ; preds = %83
%87 = sext i32 %84 to i64
%88 = getelementptr inbounds i8*, i8** %1, i64 %87
%89 = load i8*, i8** %88
%90 = call i32 @sscanf(i8* %89, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %9)
%91 = load i32, i32* %9
%92 = icmp ugt i32 %91, 31
br i1 %92, label %93, label %96
93: ; preds = %86
%94 = load i32*, i32** @stderr
%95 = call i32 (i32*, i8*, ...) @fprintf(i32* %94, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i32 %91)
br label %96
96: ; preds = %86, %93
%97 = phi i32 [ %23, %93 ], [ %91, %86 ]
br label %129
98: ; preds = %83
%99 = load i32*, i32** @stderr
%100 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i64 25, i64 1, i32* %99)
br label %129
101: ; preds = %79
%102 = load i8*, i8** %28
%103 = call i64 @strcmp(i8* %102, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
%104 = icmp eq i64 %103, 0
br i1 %104, label %105, label %115
105: ; preds = %101
%106 = add nsw i32 %26, 1
%107 = icmp slt i32 %106, %0
br i1 %107, label %108, label %112
108: ; preds = %105
%109 = sext i32 %106 to i64
%110 = getelementptr inbounds i8*, i8** %1, i64 %109
%111 = load i8*, i8** %110
br label %129
112: ; preds = %105
%113 = load i32*, i32** @stderr
%114 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.14, i64 0, i64 0), i64 27, i64 1, i32* %113)
br label %129
115: ; preds = %101
%116 = load i8*, i8** %28
%117 = call i64 @strcmp(i8* %116, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0))
%118 = icmp eq i64 %117, 0
br i1 %118, label %119, label %129
119: ; preds = %115
%120 = add nsw i32 %26, 1
%121 = icmp slt i32 %120, %0
br i1 %121, label %122, label %126
122: ; preds = %119
%123 = sext i32 %120 to i64
%124 = getelementptr inbounds i8*, i8** %1, i64 %123
%125 = load i8*, i8** %124
br label %129
126: ; preds = %119
%127 = load i32*, i32** @stderr
%128 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.16, i64 0, i64 0), i64 27, i64 1, i32* %127)
br label %129
129: ; preds = %76, %74, %112, %108, %122, %126, %115, %96, %98, %53, %54
%130 = phi i32 [ %39, %53 ], [ %26, %54 ], [ %62, %74 ], [ %26, %76 ], [ %84, %96 ], [ %26, %98 ], [ %106, %108 ], [ %26, %112 ], [ %120, %122 ], [ %26, %126 ], [ %26, %115 ]
%131 = phi i8* [ %25, %53 ], [ %25, %54 ], [ %25, %74 ], [ %25, %76 ], [ %25, %96 ], [ %25, %98 ], [ %111, %108 ], [ %25, %112 ], [ %125, %122 ], [ %25, %126 ], [ %25, %115 ]
%132 = phi i32 [ %24, %53 ], [ %24, %54 ], [ %24, %74 ], [ %24, %76 ], [ %24, %96 ], [ %24, %98 ], [ 1, %108 ], [ 1, %112 ], [ 0, %122 ], [ 0, %126 ], [ %24, %115 ]
%133 = phi i32 [ %23, %53 ], [ %23, %54 ], [ %23, %74 ], [ %23, %76 ], [ %97, %96 ], [ %23, %98 ], [ %23, %108 ], [ %23, %112 ], [ %23, %122 ], [ %23, %126 ], [ %23, %115 ]
%134 = phi i32 [ %22, %53 ], [ %22, %54 ], [ %75, %74 ], [ %22, %76 ], [ %22, %96 ], [ %22, %98 ], [ %22, %108 ], [ %22, %112 ], [ %22, %122 ], [ %22, %126 ], [ %22, %115 ]
%135 = add nsw i32 %130, 1
%136 = icmp slt i32 %135, %0
br i1 %136, label %21, label %137
137: ; preds = %129, %2
%138 = phi i8* [ null, %2 ], [ %131, %129 ]
%139 = phi i32 [ 1, %2 ], [ %132, %129 ]
%140 = phi i32 [ 0, %2 ], [ %133, %129 ]
%141 = phi i32 [ 3, %2 ], [ %134, %129 ]
%142 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.35, i64 0, i64 0))
%143 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.18, i64 0, i64 0), i32 %141, i32 %140)
%144 = call i32 @init2034(i32 0, i32 %141, i32 %140)
%145 = call i32 (...) @identify2034()
%146 = icmp eq i8* %138, null
br i1 %146, label %147, label %150
147: ; preds = %137
%148 = load i32*, i32** @stderr
%149 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.19, i64 0, i64 0), i64 77, i64 1, i32* %148)
br label %224
150: ; preds = %137
%151 = icmp eq i32 %139, 0
br i1 %151, label %195, label %152
152: ; preds = %150
%153 = call i32 @writeGPIB(i8* %11)
%154 = call i32 @readGPIB(i8* %10, i32 3)
%155 = getelementptr inbounds [1001 x i8], [1001 x i8]* %3, i64 0, i64 2
store i8 0, i8* %155
%156 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.21, i64 0, i64 0))
%157 = icmp eq i64 %156, 0
br i1 %157, label %161, label %158
158: ; preds = %152
%159 = load i32*, i32** @stderr
%160 = call i32 (i32*, i8*, ...) @fprintf(i32* %159, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.22, i64 0, i64 0), i8* %10)
br label %161
161: ; preds = %158, %152
%162 = call i32 @readGPIB(i8* %12, i32 206)
%163 = call i32 @readGPIB(i8* %13, i32 340)
%164 = call i32 @readGPIB(i8* %10, i32 2)
store i8 0, i8* %155
%165 = load i8, i8* %10
%166 = sext i8 %165 to i32
%167 = getelementptr inbounds [1001 x i8], [1001 x i8]* %3, i64 0, i64 1
%168 = load i8, i8* %167
%169 = sext i8 %168 to i32
%170 = shl nsw i32 %169, 8
%171 = add nsw i32 %170, %166
%172 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.23, i64 0, i64 0), i32 %171)
%173 = call i64 @calloc(i32 %171, i32 1)
%174 = inttoptr i64 %173 to i8*
%175 = call i32 @readGPIB(i8* %174, i32 %171)
%176 = call i32* @fopen(i8* %138, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.24, i64 0, i64 0))
%177 = icmp eq i32* %176, null
br i1 %177, label %178, label %184
178: ; preds = %161
%179 = load i32*, i32** @stderr
%180 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.25, i64 0, i64 0), i64 28, i64 1, i32* %179)
%181 = icmp eq i64 %173, 0
br i1 %181, label %224, label %182
182: ; preds = %178
%183 = call i32 @free(i8* %174)
br label %224
184: ; preds = %161
%185 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.26, i64 0, i64 0), i64 3, i64 1, i32* %176)
%186 = call i32 @fwrite(i8* %12, i32 206, i32 1, i32* %176)
%187 = call i32 @fwrite(i8* %13, i32 340, i32 1, i32* %176)
%188 = call i32 @fwrite(i8* %10, i32 2, i32 1, i32* %176)
%189 = call i32 @fwrite(i8* %174, i32 %171, i32 1, i32* %176)
%190 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.27, i64 0, i64 0), i64 1, i64 1, i32* %176)
%191 = call i32 @readGPIB(i8* %10, i32 1)
%192 = call i32 @fclose(i32* %176)
%193 = call i32 @free(i8* %174)
%194 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.28, i64 0, i64 0), i8* %138)
br label %222
195: ; preds = %150
%196 = call i32* @fopen(i8* %138, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.29, i64 0, i64 0))
%197 = icmp eq i32* %196, null
br i1 %197, label %198, label %201
198: ; preds = %195
%199 = load i32*, i32** @stderr
%200 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.30, i64 0, i64 0), i64 27, i64 1, i32* %199)
br label %224
201: ; preds = %195
%202 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.31, i64 0, i64 0), i8* %138)
%203 = load i32, i32* @SEEK_END
%204 = call i32 @fseek(i32* %196, i32 0, i32 %203)
%205 = call i32 @ftell(i32* %196)
%206 = call i32 @rewind(i32* %196)
%207 = call i64 @malloc(i32 %205)
%208 = inttoptr i64 %207 to i8*
%209 = icmp eq i64 %207, 0
br i1 %209, label %210, label %213
210: ; preds = %201
%211 = load i32*, i32** @stderr
%212 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.32, i64 0, i64 0), i64 57, i64 1, i32* %211)
br label %224
213: ; preds = %201
%214 = call i32 @fread(i8* %208, i32 1, i32 %205, i32* %196)
%215 = icmp eq i32 %214, %205
br i1 %215, label %219, label %216
216: ; preds = %213
%217 = load i32*, i32** @stderr
%218 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.33, i64 0, i64 0), i64 41, i64 1, i32* %217)
br label %224
219: ; preds = %213
%220 = call i32 @writenGPIB(i8* %208, i32 %205)
%221 = call i32 @fclose(i32* %196)
br label %222
222: ; preds = %219, %184
%223 = call i32 (...) @closeCommIEEE()
br label %224
224: ; preds = %216, %210, %178, %182, %222, %198, %147, %32
%225 = phi i32 [ 0, %32 ], [ 1, %147 ], [ 0, %222 ], [ 1, %198 ], [ 1, %182 ], [ 1, %178 ], [ 3, %216 ], [ 2, %210 ]
ret i32 %225
}