#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ create_temppath(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
unsigned char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ ioulive_main(char *, char *, char *, int, int, int);
int parse_netmap(char *, int *, int *, int *);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *, ...);
int raw_get_dev_index(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  char intf[20];
  char netmap_path[255];
  unsigned int instance;
  int i, j, raw_dev_id;
  FILE *infp;
  char linein[255];
  unsigned char ch;
  int result;
  int IOUINST, IOUINTF, IOULIVEINST;
  char tempPath[40], IOULIVE_NAME[40], IOU_NAME[40];
  printf("\nIOUlive86\n\n");
  if (argc < 4 || argc > 6) {
    print_usage();
    exit(0);
  }
  intf[0] = '\0';
  strcpy(netmap_path, "NETMAP");
  instance = 0;
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-i")) {
      if (i < argc - 1) {
        strcpy(intf, argv[i + 1]);
        i++;
        continue;
      } else {
        print_usage();
        exit(0);
      }
    } else if (!strcmp(argv[i], "-n")) {
      if (i < argc - 1) {
        strcpy(netmap_path, argv[i + 1]);
        i++;
        continue;
      } else {
        print_usage();
        exit(0);
      }
    } else if (i == argc - 1 && atoi(argv[i])) {
      instance = atoi(argv[i]);
      break;
    } else {
      print_usage();
      exit(0);
    }
  }
  if (instance == 0) {
    print_usage();
  }
  raw_dev_id = raw_get_dev_index(intf);
  if (raw_dev_id == -1) {
    printf("Error: Invalid Ethernet device specified\n");
    exit(0);
  }
  infp = fopen(netmap_path, "rt");
  if (!infp) {
    printf("Cannot open %s\n\n", netmap_path);
    exit(0);
  }
  j = 1;
  do {
    linein[0] = '\0';
    i = 0;
    while (i < 255) {
      ch = fgetc(infp);
      if (feof(infp))
        break;
      if (ch != '\n')
        linein[i++] = ch;
      else {
        j++;
        break;
      }
    }
    linein[i] = '\0';
    if (i == 255) {
      printf("Error: NETMAP file contains lines > 255 characters\n\n");
      fclose(infp);
      exit(0);
    }
    if (strlen(linein)) {
      result = parse_netmap(linein, &IOUINST, &IOUINTF, &IOULIVEINST);
      if (result) {
        fclose(infp);
        printf("ERROR: Line %d of NETMAP is invalid!\n");
        exit(0);
      }
      if (IOULIVEINST == instance)
        break;
    }
  } while (!feof(infp));
  fclose(infp);
  if (IOULIVEINST != instance) {
    printf("Error: Check NETMAP file - no mapped IOUlive86 instance found\n\n");
    exit(0);
  }
  create_temppath(tempPath);
  sprintf(IOU_NAME, "%s%d", tempPath, IOUINST);
  sprintf(IOULIVE_NAME, "%s%d", tempPath, IOULIVEINST);
  ioulive_main(IOULIVE_NAME, IOU_NAME, intf, IOUINTF, IOUINST, IOULIVEINST);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
cmpl   $0x4,-0x8(%rbp)
jl     123b <main+0x3b>
cmpl   $0x6,-0x8(%rbp)
jle    1249 <main+0x49>
mov    $0x0,%al
call   1120 <print_usage@plt>
xor    %edi,%edi
call   1110 <exit@plt>
movb   $0x0,-0x30(%rbp)
lea    -0x130(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x134(%rbp)
movl   $0x1,-0x138(%rbp)
mov    -0x138(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13e6 <main+0x1e6>
mov    -0x10(%rbp),%rax
movslq -0x138(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd7b(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    12fa <main+0xfa>
mov    -0x138(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12ec <main+0xec>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x138(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
mov    -0x138(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x138(%rbp)
jmp    13d2 <main+0x1d2>
mov    $0x0,%al
call   1120 <print_usage@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x138(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd07(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    1374 <main+0x174>
mov    -0x138(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1366 <main+0x166>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x138(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
mov    -0x138(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x138(%rbp)
jmp    13d2 <main+0x1d2>
mov    $0x0,%al
call   1120 <print_usage@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x138(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    13c4 <main+0x1c4>
mov    -0x10(%rbp),%rax
movslq -0x138(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10f0 <atoi@plt>
cmp    $0x0,%eax
je     13c4 <main+0x1c4>
mov    -0x10(%rbp),%rax
movslq -0x138(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x134(%rbp)
jmp    13e6 <main+0x1e6>
mov    $0x0,%al
call   1120 <print_usage@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x138(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x138(%rbp)
jmp    1274 <main+0x74>
cmpl   $0x0,-0x134(%rbp)
jne    13fa <main+0x1fa>
mov    $0x0,%al
call   1120 <print_usage@plt>
lea    -0x30(%rbp),%rdi
call   10d0 <raw_get_dev_index@plt>
mov    %eax,-0x140(%rbp)
cmpl   $0xffffffff,-0x140(%rbp)
jne    142b <main+0x22b>
lea    0xbfd(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    -0x130(%rbp),%rdi
lea    0xc0b(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
jne    146f <main+0x26f>
lea    -0x130(%rbp),%rsi
lea    0xbe6(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
movl   $0x1,-0x13c(%rbp)
movb   $0x0,-0x250(%rbp)
movl   $0x0,-0x138(%rbp)
cmpl   $0xff,-0x138(%rbp)
jge    1515 <main+0x315>
mov    -0x148(%rbp),%rdi
call   10a0 <fgetc@plt>
mov    %al,-0x251(%rbp)
mov    -0x148(%rbp),%rdi
call   10c0 <feof@plt>
cmp    $0x0,%rax
je     14c7 <main+0x2c7>
jmp    1515 <main+0x315>
movzbl -0x251(%rbp),%eax
cmp    $0xa,%eax
je     14fc <main+0x2fc>
mov    -0x251(%rbp),%cl
mov    -0x138(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x138(%rbp)
cltq
mov    %cl,-0x250(%rbp,%rax,1)
jmp    1510 <main+0x310>
mov    -0x13c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13c(%rbp)
jmp    1515 <main+0x315>
jmp    148a <main+0x28a>
movslq -0x138(%rbp),%rax
movb   $0x0,-0x250(%rbp,%rax,1)
cmpl   $0xff,-0x138(%rbp)
jne    1555 <main+0x355>
lea    0xb1d(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x148(%rbp),%rdi
call   1060 <fclose@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    -0x250(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x0,%rax
je     15dc <main+0x3dc>
lea    -0x250(%rbp),%rdi
lea    -0x25c(%rbp),%rsi
lea    -0x260(%rbp),%rdx
lea    -0x264(%rbp),%rcx
call   1080 <parse_netmap@plt>
mov    %eax,-0x258(%rbp)
cmpl   $0x0,-0x258(%rbp)
je     15c0 <main+0x3c0>
mov    -0x148(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xadb(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x264(%rbp),%eax
cmp    -0x134(%rbp),%eax
jne    15d7 <main+0x3d7>
jmp    15fe <main+0x3fe>
jmp    15dc <main+0x3dc>
jmp    15e1 <main+0x3e1>
mov    -0x148(%rbp),%rdi
call   10c0 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1479 <main+0x279>
mov    -0x148(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x264(%rbp),%eax
cmp    -0x134(%rbp),%eax
je     1631 <main+0x431>
lea    0xa90(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    -0x290(%rbp),%rdi
call   1050 <create_temppath@plt>
lea    -0x2f0(%rbp),%rdi
lea    -0x290(%rbp),%rdx
mov    -0x25c(%rbp),%ecx
lea    0xa9b(%rip),%rsi
call   1100 <sprintf@plt>
lea    -0x2c0(%rbp),%rdi
lea    -0x290(%rbp),%rdx
mov    -0x264(%rbp),%ecx
lea    0xa7b(%rip),%rsi
call   1100 <sprintf@plt>
lea    -0x2c0(%rbp),%rdi
lea    -0x2f0(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    -0x260(%rbp),%ecx
mov    -0x25c(%rbp),%r8d
mov    -0x264(%rbp),%r9d
call   1030 <ioulive_main@plt>
mov    -0x4(%rbp),%eax
add    $0x2f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2c8,%rsp
mov    %rsi,%rbp
mov    %edi,%r13d
lea    0xe2e(%rip),%rdi
call   1050 <puts@plt>
lea    -0x7(%r13),%eax
cmp    $0xfffffffc,%eax
jbe    1479 <main+0x279>
movb   $0x0,0x10(%rsp)
lea    0xdc4(%rip),%rsi
lea    0x1c0(%rsp),%rdi
call   1040 <strcpy@plt>
lea    -0x1(%r13),%r12d
xor    %r14d,%r14d
lea    0x1(%r14),%r15
mov    0x8(%rbp,%r14,8),%rbx
mov    %rbx,%rdi
lea    0xda4(%rip),%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     12a0 <main+0xa0>
mov    %rbx,%rdi
lea    0xd94(%rip),%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
jne    12d0 <main+0xd0>
lea    0x1c0(%rsp),%rdi
cmp    %r12d,%r15d
jl     12ae <main+0xae>
jmp    1479 <main+0x279>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x10(%rsp),%rdi
cmp    %r12d,%r15d
jge    1479 <main+0x279>
mov    0x10(%rbp,%r14,8),%rsi
call   1040 <strcpy@plt>
add    $0x2,%r14
lea    0x1(%r14),%eax
cmp    %r13d,%eax
jl     1250 <main+0x50>
xor    %ebp,%ebp
xor    %eax,%eax
call   1120 <print_usage@plt>
jmp    12ef <main+0xef>
add    $0xfffffffe,%r13d
cmp    %r14d,%r13d
jne    1479 <main+0x279>
mov    %rbx,%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1479 <main+0x279>
lea    0x10(%rsp),%rdi
call   10d0 <raw_get_dev_index@plt>
cmp    $0xffffffff,%eax
je     14a4 <main+0x2a4>
lea    0xd04(%rip),%rsi
lea    0x1c0(%rsp),%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     14ad <main+0x2ad>
mov    %rax,%rbx
lea    0xc(%rsp),%r12
lea    0x4(%rsp),%r13
jmp    1341 <main+0x141>
xchg   %ax,%ax
mov    %rbx,%rdi
call   10c0 <feof@plt>
test   %rax,%rax
jne    13cd <main+0x1cd>
movb   $0x0,0xc0(%rsp)
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %rbx,%rdi
call   10a0 <fgetc@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   10c0 <feof@plt>
test   %rax,%rax
jne    1390 <main+0x190>
cmp    $0xa,%r14b
je     1390 <main+0x190>
mov    %r14b,0xc0(%rsp,%r15,1)
add    $0x1,%r15
cmp    $0xff,%r15
jne    1350 <main+0x150>
jmp    1456 <main+0x256>
nopl   0x0(%rax,%rax,1)
movb   $0x0,0xc0(%rsp,%r15,1)
cmpb   $0x0,0xc0(%rsp)
je     1330 <main+0x130>
lea    0xc0(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1080 <parse_netmap@plt>
test   %eax,%eax
jne    1487 <main+0x287>
cmp    %ebp,0x4(%rsp)
jne    1330 <main+0x130>
mov    %rbx,%rdi
call   1070 <fclose@plt>
cmp    %ebp,0x4(%rsp)
jne    14ca <main+0x2ca>
lea    0x90(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <create_temppath@plt>
mov    0x8(%rsp),%ecx
lea    0xc4d(%rip),%rbp
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1100 <sprintf@plt>
mov    0x4(%rsp),%ecx
lea    0x60(%rsp),%r15
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1100 <sprintf@plt>
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0x4(%rsp),%r9d
lea    0x10(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <ioulive_main@plt>
xor    %eax,%eax
add    $0x2c8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,0x1bf(%rsp)
lea    0xc32(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
xor    %edi,%edi
call   1110 <exit@plt>
xor    %eax,%eax
call   1120 <print_usage@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xb8b(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    0xc20(%rip),%rdi
jmp    14d1 <main+0x2d1>
lea    0xb5c(%rip),%rdi
lea    0x1c0(%rsp),%rsi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
lea    0xb87(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"\0AIOUlive86\0A\0A\00"
@.str.1 = [7 x i8] c"NETMAP\00"
@.str.2 = [3 x i8] c"-i\00"
@.str.3 = [3 x i8] c"-n\00"
@.str.4 = [42 x i8] c"Error: Invalid Ethernet device specified\0A\00"
@.str.5 = [3 x i8] c"rt\00"
@.str.6 = [17 x i8] c"Cannot open %s\0A\0A\00"
@.str.7 = [53 x i8] c"Error: NETMAP file contains lines > 255 characters\0A\0A\00"
@.str.8 = [38 x i8] c"ERROR: Line %d of NETMAP is invalid!\0A\00"
@.str.9 = [64 x i8] c"Error: Check NETMAP file - no mapped IOUlive86 instance found\0A\0A\00"
@.str.10 = [5 x i8] c"%s%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i8]
%7 = alloca [255 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca [255 x i8]
%14 = alloca i8
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca [40 x i8]
%20 = alloca [40 x i8]
%21 = alloca [40 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 4
br i1 %24, label %28, label %25
25: ; preds = %2
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 6
br i1 %27, label %28, label %31
28: ; preds = %25, %2
%29 = call i32 (...) @print_usage()
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %25
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
store i8 0, i8* %32
%33 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%34 = call i32 @strcpy(i8* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
store i32 1, i32* %9
br label %35
35: ; preds = %116, %31
%36 = load i32, i32* %9
%37 = load i32, i32* %4
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %119
39: ; preds = %35
%40 = load i8**, i8*** %5
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @strcmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp ne i32 %45, 0
br i1 %46, label %66, label %47
47: ; preds = %39
%48 = load i32, i32* %9
%49 = load i32, i32* %4
%50 = sub nsw i32 %49, 1
%51 = icmp slt i32 %48, %50
br i1 %51, label %52, label %63
52: ; preds = %47
%53 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%54 = load i8**, i8*** %5
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %54, i64 %57
%59 = load i8*, i8** %58
%60 = call i32 @strcpy(i8* %53, i8* %59)
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %116
63: ; preds = %47
%64 = call i32 (...) @print_usage()
%65 = call i32 @exit(i32 0)
unreachable
66: ; preds = %39
%67 = load i8**, i8*** %5
%68 = load i32, i32* %9
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = call i32 @strcmp(i8* %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%73 = icmp ne i32 %72, 0
br i1 %73, label %93, label %74
74: ; preds = %66
%75 = load i32, i32* %9
%76 = load i32, i32* %4
%77 = sub nsw i32 %76, 1
%78 = icmp slt i32 %75, %77
br i1 %78, label %79, label %90
79: ; preds = %74
%80 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%81 = load i8**, i8*** %5
%82 = load i32, i32* %9
%83 = add nsw i32 %82, 1
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %81, i64 %84
%86 = load i8*, i8** %85
%87 = call i32 @strcpy(i8* %80, i8* %86)
%88 = load i32, i32* %9
%89 = add nsw i32 %88, 1
store i32 %89, i32* %9
br label %116
90: ; preds = %74
%91 = call i32 (...) @print_usage()
%92 = call i32 @exit(i32 0)
unreachable
93: ; preds = %66
%94 = load i32, i32* %9
%95 = load i32, i32* %4
%96 = sub nsw i32 %95, 1
%97 = icmp eq i32 %94, %96
br i1 %97, label %98, label %113
98: ; preds = %93
%99 = load i8**, i8*** %5
%100 = load i32, i32* %9
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8*, i8** %99, i64 %101
%103 = load i8*, i8** %102
%104 = call i32 @atoi(i8* %103)
%105 = icmp ne i32 %104, 0
br i1 %105, label %106, label %113
106: ; preds = %98
%107 = load i8**, i8*** %5
%108 = load i32, i32* %9
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8*, i8** %107, i64 %109
%111 = load i8*, i8** %110
%112 = call i32 @atoi(i8* %111)
store i32 %112, i32* %8
br label %119
113: ; preds = %98, %93
%114 = call i32 (...) @print_usage()
%115 = call i32 @exit(i32 0)
unreachable
116: ; preds = %79, %52
%117 = load i32, i32* %9
%118 = add nsw i32 %117, 1
store i32 %118, i32* %9
br label %35
119: ; preds = %106, %35
%120 = load i32, i32* %8
%121 = icmp eq i32 %120, 0
br i1 %121, label %122, label %124
122: ; preds = %119
%123 = call i32 (...) @print_usage()
br label %124
124: ; preds = %122, %119
%125 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%126 = call i32 @raw_get_dev_index(i8* %125)
store i32 %126, i32* %11
%127 = load i32, i32* %11
%128 = icmp eq i32 %127, -1
br i1 %128, label %129, label %132
129: ; preds = %124
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%131 = call i32 @exit(i32 0)
unreachable
132: ; preds = %124
%133 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%134 = call i32* @fopen(i8* %133, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %134, i32** %12
%135 = load i32*, i32** %12
%136 = icmp ne i32* %135, null
br i1 %136, label %141, label %137
137: ; preds = %132
%138 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %138)
%140 = call i32 @exit(i32 0)
unreachable
141: ; preds = %132
store i32 1, i32* %10
br label %142
142: ; preds = %200, %141
%143 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 0
store i8 0, i8* %143
store i32 0, i32* %9
br label %144
144: ; preds = %167, %142
%145 = load i32, i32* %9
%146 = icmp slt i32 %145, 255
br i1 %146, label %147, label %168
147: ; preds = %144
%148 = load i32*, i32** %12
%149 = call zeroext i8 @fgetc(i32* %148)
store i8 %149, i8* %14
%150 = load i32*, i32** %12
%151 = call i64 @feof(i32* %150)
%152 = icmp ne i64 %151, 0
br i1 %152, label %153, label %154
153: ; preds = %147
br label %168
154: ; preds = %147
%155 = load i8, i8* %14
%156 = zext i8 %155 to i32
%157 = icmp ne i32 %156, 10
br i1 %157, label %158, label %164
158: ; preds = %154
%159 = load i8, i8* %14
%160 = load i32, i32* %9
%161 = add nsw i32 %160, 1
store i32 %161, i32* %9
%162 = sext i32 %160 to i64
%163 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 %162
store i8 %159, i8* %163
br label %167
164: ; preds = %154
%165 = load i32, i32* %10
%166 = add nsw i32 %165, 1
store i32 %166, i32* %10
br label %168
167: ; preds = %158
br label %144
168: ; preds = %164, %153, %144
%169 = load i32, i32* %9
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 %170
store i8 0, i8* %171
%172 = load i32, i32* %9
%173 = icmp eq i32 %172, 255
br i1 %173, label %174, label %179
174: ; preds = %168
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0))
%176 = load i32*, i32** %12
%177 = call i32 @fclose(i32* %176)
%178 = call i32 @exit(i32 0)
unreachable
179: ; preds = %168
%180 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 0
%181 = call i64 @strlen(i8* %180)
%182 = icmp ne i64 %181, 0
br i1 %182, label %183, label %199
183: ; preds = %179
%184 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 0
%185 = call i32 @parse_netmap(i8* %184, i32* %16, i32* %17, i32* %18)
store i32 %185, i32* %15
%186 = load i32, i32* %15
%187 = icmp ne i32 %186, 0
br i1 %187, label %188, label %193
188: ; preds = %183
%189 = load i32*, i32** %12
%190 = call i32 @fclose(i32* %189)
%191 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
%192 = call i32 @exit(i32 0)
unreachable
193: ; preds = %183
%194 = load i32, i32* %18
%195 = load i32, i32* %8
%196 = icmp eq i32 %194, %195
br i1 %196, label %197, label %198
197: ; preds = %193
br label %205
198: ; preds = %193
br label %199
199: ; preds = %198, %179
br label %200
200: ; preds = %199
%201 = load i32*, i32** %12
%202 = call i64 @feof(i32* %201)
%203 = icmp ne i64 %202, 0
%204 = xor i1 %203, true
br i1 %204, label %142, label %205
205: ; preds = %200, %197
%206 = load i32*, i32** %12
%207 = call i32 @fclose(i32* %206)
%208 = load i32, i32* %18
%209 = load i32, i32* %8
%210 = icmp ne i32 %208, %209
br i1 %210, label %211, label %214
211: ; preds = %205
%212 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.9, i64 0, i64 0))
%213 = call i32 @exit(i32 0)
unreachable
214: ; preds = %205
%215 = getelementptr inbounds [40 x i8], [40 x i8]* %19, i64 0, i64 0
%216 = call i32 @create_temppath(i8* %215)
%217 = getelementptr inbounds [40 x i8], [40 x i8]* %21, i64 0, i64 0
%218 = getelementptr inbounds [40 x i8], [40 x i8]* %19, i64 0, i64 0
%219 = load i32, i32* %16
%220 = call i32 @sprintf(i8* %217, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* %218, i32 %219)
%221 = getelementptr inbounds [40 x i8], [40 x i8]* %20, i64 0, i64 0
%222 = getelementptr inbounds [40 x i8], [40 x i8]* %19, i64 0, i64 0
%223 = load i32, i32* %18
%224 = call i32 @sprintf(i8* %221, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* %222, i32 %223)
%225 = getelementptr inbounds [40 x i8], [40 x i8]* %20, i64 0, i64 0
%226 = getelementptr inbounds [40 x i8], [40 x i8]* %21, i64 0, i64 0
%227 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%228 = load i32, i32* %17
%229 = load i32, i32* %16
%230 = load i32, i32* %18
%231 = call i32 @ioulive_main(i8* %225, i8* %226, i8* %227, i32 %228, i32 %229, i32 %230)
%232 = load i32, i32* %3
ret i32 %232
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"NETMAP\00"
@.str.2 = [3 x i8] c"-i\00"
@.str.3 = [3 x i8] c"-n\00"
@.str.5 = [3 x i8] c"rt\00"
@.str.6 = [17 x i8] c"Cannot open %s\0A\0A\00"
@.str.8 = [38 x i8] c"ERROR: Line %d of NETMAP is invalid!\0A\00"
@.str.10 = [5 x i8] c"%s%d\00"
@str = [12 x i8] c"\0AIOUlive86\0A\00"
@str.11 = [63 x i8] c"Error: Check NETMAP file - no mapped IOUlive86 instance found\0A\00"
@str.12 = [52 x i8] c"Error: NETMAP file contains lines > 255 characters\0A\00"
@str.13 = [41 x i8] c"Error: Invalid Ethernet device specified\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = alloca [255 x i8]
%5 = alloca [255 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [40 x i8]
%10 = alloca [40 x i8]
%11 = alloca [40 x i8]
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%15 = bitcast i32* %6 to i8*
%16 = bitcast i32* %7 to i8*
%17 = bitcast i32* %8 to i8*
%18 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%19 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%20 = getelementptr inbounds [40 x i8], [40 x i8]* %11, i64 0, i64 0
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%22 = add i32 %0, -7
%23 = icmp ult i32 %22, -3
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = tail call i32 (...) @print_usage()
%26 = tail call i32 @exit(i32 0)
unreachable
27: ; preds = %2
store i8 0, i8* %12
%28 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%29 = add nsw i32 %0, -1
br label %30
30: ; preds = %27, %58
%31 = phi i32 [ 1, %27 ], [ %65, %58 ]
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %1, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @strcmp(i8* dereferenceable(1) %34, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %30
%38 = icmp slt i32 %31, %29
br i1 %38, label %58, label %39
39: ; preds = %37
%40 = call i32 (...) @print_usage()
%41 = call i32 @exit(i32 0)
unreachable
42: ; preds = %30
%43 = call i32 @strcmp(i8* dereferenceable(1) %34, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = icmp slt i32 %31, %29
br i1 %46, label %58, label %47
47: ; preds = %45
%48 = call i32 (...) @print_usage()
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %42
%51 = icmp eq i32 %31, %29
br i1 %51, label %52, label %55
52: ; preds = %50
%53 = call i32 @atoi(i8* %34)
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %69
55: ; preds = %52, %50
%56 = call i32 (...) @print_usage()
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %45, %37
%59 = phi i8* [ %12, %37 ], [ %13, %45 ]
%60 = add nuw nsw i32 %31, 1
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %1, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 @strcpy(i8* %59, i8* %63)
%65 = add nuw nsw i32 %31, 2
%66 = icmp slt i32 %65, %0
br i1 %66, label %30, label %67
67: ; preds = %58
%68 = call i32 (...) @print_usage()
br label %69
69: ; preds = %52, %67
%70 = phi i32 [ 0, %67 ], [ %53, %52 ]
%71 = call i32 @raw_get_dev_index(i8* %12)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %69
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.13, i64 0, i64 0))
%75 = call i32 @exit(i32 0)
unreachable
76: ; preds = %69
%77 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%78 = icmp eq i32* %77, null
br i1 %78, label %79, label %82
79: ; preds = %76
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %13)
%81 = call i32 @exit(i32 0)
unreachable
82: ; preds = %76, %114
store i8 0, i8* %14
br label %83
83: ; preds = %82, %90
%84 = phi i64 [ 0, %82 ], [ %91, %90 ]
%85 = call zeroext i8 @fgetc(i32* %77)
%86 = call i64 @feof(i32* %77)
%87 = icmp ne i64 %86, 0
%88 = icmp eq i8 %85, 10
%89 = or i1 %87, %88
br i1 %89, label %99, label %90
90: ; preds = %83
%91 = add nuw nsw i64 %84, 1
%92 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 %84
store i8 %85, i8* %92
%93 = icmp eq i64 %91, 255
br i1 %93, label %94, label %83
94: ; preds = %90
%95 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 255
store i8 0, i8* %95
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.12, i64 0, i64 0))
%97 = call i32 @fclose(i32* %77)
%98 = call i32 @exit(i32 0)
unreachable
99: ; preds = %83
%100 = and i64 %84, 4294967295
%101 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 %100
store i8 0, i8* %101
%102 = load i8, i8* %14
%103 = icmp eq i8 %102, 0
br i1 %103, label %114, label %104
104: ; preds = %99
%105 = call i32 @parse_netmap(i8* %14, i32* %6, i32* %7, i32* %8)
%106 = icmp eq i32 %105, 0
br i1 %106, label %111, label %107
107: ; preds = %104
%108 = call i32 @fclose(i32* %77)
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
%110 = call i32 @exit(i32 0)
unreachable
111: ; preds = %104
%112 = load i32, i32* %8
%113 = icmp eq i32 %112, %70
br i1 %113, label %117, label %114
114: ; preds = %99, %111
%115 = call i64 @feof(i32* %77)
%116 = icmp eq i64 %115, 0
br i1 %116, label %82, label %117
117: ; preds = %111, %114
%118 = call i32 @fclose(i32* %77)
%119 = load i32, i32* %8
%120 = icmp eq i32 %119, %70
br i1 %120, label %124, label %121
121: ; preds = %117
%122 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.11, i64 0, i64 0))
%123 = call i32 @exit(i32 0)
unreachable
124: ; preds = %117
%125 = call i32 @create_temppath(i8* %18)
%126 = load i32, i32* %6
%127 = call i32 @sprintf(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* %18, i32 %126)
%128 = load i32, i32* %8
%129 = call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8* %18, i32 %128)
%130 = load i32, i32* %7
%131 = load i32, i32* %6
%132 = load i32, i32* %8
%133 = call i32 @ioulive_main(i8* %19, i8* %20, i8* %12, i32 %130, i32 %131, i32 %132)
ret i32 0
}