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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *homfly_str(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char name[2048];
  char input[2048];
  char test[2048];
  char *out;
  int i;
  FILE *f;
  if (argc != 2) {
    printf("must give exactly one file to test\n");
    return 2;
  }
  f = fopen(argv[1], "r");
  if (f == NULL) {
    fclose(f);
    return 1;
  }
  while (fgets(name, sizeof(name), f) != NULL) {
    if (fgets(input, sizeof(input), f) == NULL) {
      fclose(f);
      printf("missing link data");
      return 3;
    }
    if (fgets(test, sizeof(test), f) == NULL) {
      fclose(f);
      printf("missing output data");
      return 3;
    }
    name[strlen(name) - 1] = '\0';
    input[strlen(input) - 1] = '\0';
    test[strlen(test) - 1] = '\0';
    out = homfly_str(input);
    if (strcmp(test, out) != 0) {
      printf("error in computation: %s\n", name);
      printf("expected: %s\n", test);
      printf("got     : %s\n", out);
      fclose(f);
      return 1;
    }
  }
  printf("correct result\n");
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ad <main+0x3d>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    139d <main+0x22d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe68(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x1828(%rbp)
cmpq   $0x0,-0x1828(%rbp)
jne    11ee <main+0x7e>
mov    -0x1828(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    139d <main+0x22d>
jmp    11f3 <main+0x83>
lea    -0x810(%rbp),%rdi
mov    -0x1828(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     137c <main+0x20c>
lea    -0x1010(%rbp),%rdi
mov    -0x1828(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    125d <main+0xed>
mov    -0x1828(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    139d <main+0x22d>
lea    -0x1810(%rbp),%rdi
mov    -0x1828(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    12a5 <main+0x135>
mov    -0x1828(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    139d <main+0x22d>
lea    -0x810(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x810(%rbp,%rax,1)
lea    -0x1010(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x1010(%rbp,%rax,1)
lea    -0x1810(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x1810(%rbp,%rax,1)
lea    -0x1010(%rbp),%rdi
call   1080 <homfly_str@plt>
mov    %rax,-0x1818(%rbp)
lea    -0x1810(%rbp),%rdi
mov    -0x1818(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1377 <main+0x207>
lea    -0x810(%rbp),%rsi
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1810(%rbp),%rsi
lea    0xd23(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1818(%rbp),%rsi
lea    0xd1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1828(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    139d <main+0x22d>
jmp    11f3 <main+0x83>
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1828(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1800,%rsp
cmp    $0x2,%edi
jne    12a7 <main+0x127>
mov    0x8(%rsi),%rdi
lea    0xe5c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12ba <main+0x13a>
mov    %rax,%r13
lea    0x800(%rsp),%r14
lea    0x1000(%rsp),%r15
mov    %rsp,%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x800,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12c8 <main+0x148>
mov    %r15,%rdi
mov    $0x800,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12e0 <main+0x160>
mov    %r12,%rdi
mov    $0x800,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12f1 <main+0x171>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
mov    %r12,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
mov    %r15,%rdi
call   1090 <homfly_str@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11d0 <main+0x50>
lea    0xdb7(%rip),%rdi
lea    0x800(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdbb(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdb8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
jmp    12bc <main+0x13c>
lea    0xdbf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
jmp    130c <main+0x18c>
xor    %edi,%edi
call   1040 <fclose@plt>
mov    $0x1,%eax
jmp    130c <main+0x18c>
lea    0xd8f(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    130c <main+0x18c>
mov    %r13,%rdi
call   1040 <fclose@plt>
lea    0xd13(%rip),%rdi
jmp    1300 <main+0x180>
mov    %r13,%rdi
call   1040 <fclose@plt>
lea    0xd14(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x3,%eax
add    $0x1800,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [36 x i8] c"must give exactly one file to test\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"missing link data\00"
@.str.3 = [20 x i8] c"missing output data\00"
@.str.4 = [26 x i8] c"error in computation: %s\0A\00"
@.str.5 = [14 x i8] c"expected: %s\0A\00"
@.str.6 = [14 x i8] c"got : %s\0A\00"
@.str.7 = [16 x i8] c"correct result\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2048 x i8]
%7 = alloca [2048 x i8]
%8 = alloca [2048 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %86
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %11
%21 = load i32*, i32** %11
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32*, i32** %11
%25 = call i32 @fclose(i32* %24)
store i32 1, i32* %3
br label %86
26: ; preds = %16
br label %27
27: ; preds = %81, %26
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%29 = load i32*, i32** %11
%30 = call i32* @fgets(i8* %28, i32 2048, i32* %29)
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %82
32: ; preds = %27
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%34 = load i32*, i32** %11
%35 = call i32* @fgets(i8* %33, i32 2048, i32* %34)
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i32*, i32** %11
%39 = call i32 @fclose(i32* %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 3, i32* %3
br label %86
41: ; preds = %32
%42 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%43 = load i32*, i32** %11
%44 = call i32* @fgets(i8* %42, i32 2048, i32* %43)
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = load i32*, i32** %11
%48 = call i32 @fclose(i32* %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 3, i32* %3
br label %86
50: ; preds = %41
%51 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%52 = call i32 @strlen(i8* %51)
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 %54
store i8 0, i8* %55
%56 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%57 = call i32 @strlen(i8* %56)
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 %59
store i8 0, i8* %60
%61 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = sub nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 %64
store i8 0, i8* %65
%66 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%67 = call i8* @homfly_str(i8* %66)
store i8* %67, i8** %9
%68 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%69 = load i8*, i8** %9
%70 = call i64 @strcmp(i8* %68, i8* %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %81
72: ; preds = %50
%73 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %73)
%75 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %75)
%77 = load i8*, i8** %9
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %77)
%79 = load i32*, i32** %11
%80 = call i32 @fclose(i32* %79)
store i32 1, i32* %3
br label %86
81: ; preds = %50
br label %27
82: ; preds = %27
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%84 = load i32*, i32** %11
%85 = call i32 @fclose(i32* %84)
store i32 0, i32* %3
br label %86
86: ; preds = %82, %72, %46, %37, %23, %14
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"missing link data\00"
@.str.3 = [20 x i8] c"missing output data\00"
@.str.4 = [26 x i8] c"error in computation: %s\0A\00"
@.str.5 = [14 x i8] c"expected: %s\0A\00"
@.str.6 = [14 x i8] c"got : %s\0A\00"
@str = [15 x i8] c"correct result\00"
@str.8 = [35 x i8] c"must give exactly one file to test\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = alloca [2048 x i8]
%5 = alloca [2048 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.8, i64 0, i64 0))
br label %58
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @fclose(i32* null)
br label %58
19: ; preds = %12, %34
%20 = call i32* @fgets(i8* %6, i32 2048, i32* %15)
%21 = icmp eq i32* %20, null
br i1 %21, label %55, label %22
22: ; preds = %19
%23 = call i32* @fgets(i8* %7, i32 2048, i32* %15)
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = call i32 @fclose(i32* %15)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %58
28: ; preds = %22
%29 = call i32* @fgets(i8* %8, i32 2048, i32* %15)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = call i32 @fclose(i32* %15)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %58
34: ; preds = %28
%35 = call i32 @strlen(i8* %6)
%36 = add nsw i32 %35, -1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %37
store i8 0, i8* %38
%39 = call i32 @strlen(i8* %7)
%40 = add nsw i32 %39, -1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %41
store i8 0, i8* %42
%43 = call i32 @strlen(i8* %8)
%44 = add nsw i32 %43, -1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 %45
store i8 0, i8* %46
%47 = call i8* @homfly_str(i8* %7)
%48 = call i64 @strcmp(i8* %8, i8* %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %19, label %50
50: ; preds = %34
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %47)
%54 = call i32 @fclose(i32* %15)
br label %58
55: ; preds = %19
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%57 = call i32 @fclose(i32* %15)
br label %58
58: ; preds = %55, %50, %31, %25, %17, %10
%59 = phi i32 [ 2, %10 ], [ 1, %17 ], [ 3, %25 ], [ 3, %31 ], [ 1, %50 ], [ 0, %55 ]
ret i32 %59
}