#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int i;
  char inname1[1000], inname2[1000], outname[1000];
  char line[1000], line2[1000];
  char source[1000], source2[1000];
  FILE *ifp, *ifp2, *ofp;
  printf("Enter the name of the file containing the source list:  ");
  gets(inname1);
  printf("Enter the name of the file containing the fluxes/indices\n");
  printf("  to be extracted:  ");
  gets(inname2);
  printf("Enter the name of the output file:  ");
  gets(outname);
  ifp = fopen(inname1, "r");
  ofp = fopen(outname, "w");
  i = 0;
  while (fgets(line, 1000, ifp) != NULL) {
    sscanf(line, "%s", source);
    i++;
    printf("%d %s\n", i, source);
    ifp2 = fopen(inname2, "r");
    while (fgets(line2, 1000, ifp2) != NULL) {
      sscanf(line2, "%s", source2);
      if (strcmp(source, source2) == 0) {
        fputs(line2, ofp);
        break;
      }
    }
    fclose(ifp2);
  }
  fclose(ofp);
  fclose(ifp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1bc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x400(%rbp),%rdi
call   1080 <gets@plt>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x7f0(%rbp),%rdi
call   1080 <gets@plt>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xbe0(%rbp),%rdi
call   1080 <gets@plt>
lea    -0x400(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x1ba8(%rbp)
lea    -0xbe0(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x1bb8(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0xfd0(%rbp),%rdi
mov    -0x1ba8(%rbp),%rdx
mov    $0x3e8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     132e <main+0x1ae>
lea    -0xfd0(%rbp),%rdi
lea    -0x17b0(%rbp),%rdx
lea    0xe4a(%rip),%rsi
call   1090 <sscanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x17b0(%rbp),%rdx
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x7f0(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x1bb0(%rbp)
lea    -0x13c0(%rbp),%rdi
mov    -0x1bb0(%rbp),%rdx
mov    $0x3e8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     131d <main+0x19d>
lea    -0x13c0(%rbp),%rdi
lea    -0x1ba0(%rbp),%rdx
lea    0xdd3(%rip),%rsi
call   1090 <sscanf@plt>
lea    -0x17b0(%rbp),%rdi
lea    -0x1ba0(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1318 <main+0x198>
lea    -0x13c0(%rbp),%rdi
mov    -0x1bb8(%rbp),%rsi
call   1050 <fputs@plt>
jmp    131d <main+0x19d>
jmp    12a7 <main+0x127>
mov    -0x1bb0(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1230 <main+0xb0>
mov    -0x1bb8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1ba8(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x1bc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1ba8,%rsp
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x17c0(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <gets@plt>
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x410(%rsp),%rdi
call   1090 <gets@plt>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x13d0(%rsp),%rbp
mov    %rbp,%rdi
call   1090 <gets@plt>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
lea    0xe58(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
mov    %rax,0x10(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1339 <main+0x1a9>
lea    0xe26(%rip),%r13
lea    0x20(%rsp),%r12
lea    0xbf0(%rsp),%r15
lea    0xfe0(%rsp),%r14
lea    0x800(%rsp),%rbp
xor    %ebx,%ebx
jmp    12ac <main+0x11c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1040 <fclose@plt>
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    $0x3e8,%esi
mov    0x18(%rsp),%rdx
call   1070 <fgets@plt>
test   %rax,%rax
mov    0xc(%rsp),%ebx
je     1339 <main+0x1a9>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   10a0 <sscanf@plt>
add    $0x1,%ebx
lea    0xdb6(%rip),%rdi
mov    %ebx,0xc(%rsp)
mov    %ebx,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x410(%rsp),%rdi
lea    0xd90(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x3e8,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1280 <main+0xf0>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   10a0 <sscanf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    12f0 <main+0x160>
mov    %r14,%rdi
mov    0x10(%rsp),%rsi
call   1060 <fputs@plt>
jmp    1280 <main+0xf0>
mov    0x10(%rsp),%rdi
call   1040 <fclose@plt>
mov    0x18(%rsp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x1ba8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [57 x i8] c"Enter the name of the file containing the source list: \00"
@.str.1 = [58 x i8] c"Enter the name of the file containing the fluxes/indices\0A\00"
@.str.2 = [21 x i8] c" to be extracted: \00"
@.str.3 = [37 x i8] c"Enter the name of the output file: \00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [7 x i8] c"%d %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1000 x i8]
%8 = alloca [1000 x i8]
%9 = alloca [1000 x i8]
%10 = alloca [1000 x i8]
%11 = alloca [1000 x i8]
%12 = alloca [1000 x i8]
%13 = alloca [1000 x i8]
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%19 = call i32 @gets(i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%23 = call i32 @gets(i8* %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%26 = call i32 @gets(i8* %25)
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %28, i32** %14
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %30, i32** %16
store i32 0, i32* %6
br label %31
31: ; preds = %65, %2
%32 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%33 = load i32*, i32** %14
%34 = call i32* @fgets(i8* %32, i32 1000, i32* %33)
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %68
36: ; preds = %31
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%38 = getelementptr inbounds [1000 x i8], [1000 x i8]* %12, i64 0, i64 0
%39 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %38)
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %12, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %42, i8* %43)
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %46, i32** %15
br label %47
47: ; preds = %64, %36
%48 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%49 = load i32*, i32** %15
%50 = call i32* @fgets(i8* %48, i32 1000, i32* %49)
%51 = icmp ne i32* %50, null
br i1 %51, label %52, label %65
52: ; preds = %47
%53 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%54 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%55 = call i32 @sscanf(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %54)
%56 = getelementptr inbounds [1000 x i8], [1000 x i8]* %12, i64 0, i64 0
%57 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%58 = call i64 @strcmp(i8* %56, i8* %57)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %52
%61 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%62 = load i32*, i32** %16
%63 = call i32 @fputs(i8* %61, i32* %62)
br label %65
64: ; preds = %52
br label %47
65: ; preds = %60, %47
%66 = load i32*, i32** %15
%67 = call i32 @fclose(i32* %66)
br label %31
68: ; preds = %31
%69 = load i32*, i32** %16
%70 = call i32 @fclose(i32* %69)
%71 = load i32*, i32** %14
%72 = call i32 @fclose(i32* %71)
ret i32 0
}

LLVM IR (-O2):
@.str = [57 x i8] c"Enter the name of the file containing the source list: \00"
@.str.2 = [21 x i8] c" to be extracted: \00"
@.str.3 = [37 x i8] c"Enter the name of the output file: \00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [7 x i8] c"%d %s\0A\00"
@str = [57 x i8] c"Enter the name of the file containing the fluxes/indices\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000 x i8]
%4 = alloca [1000 x i8]
%5 = alloca [1000 x i8]
%6 = alloca [1000 x i8]
%7 = alloca [1000 x i8]
%8 = alloca [1000 x i8]
%9 = alloca [1000 x i8]
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @gets(i8* %10)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @gets(i8* %11)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @gets(i8* %12)
%24 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32* @fgets(i8* %13, i32 1000, i32* %24)
%27 = icmp eq i32* %26, null
br i1 %27, label %47, label %28
28: ; preds = %2, %43
%29 = phi i32 [ %31, %43 ], [ 0, %2 ]
%30 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %15)
%31 = add nuw nsw i32 %29, 1
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %31, i8* %15)
%33 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %37, %28
%35 = call i32* @fgets(i8* %14, i32 1000, i32* %33)
%36 = icmp eq i32* %35, null
br i1 %36, label %43, label %37
37: ; preds = %34
%38 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %16)
%39 = call i64 @strcmp(i8* %15, i8* %16)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %34
41: ; preds = %37
%42 = call i32 @fputs(i8* %14, i32* %25)
br label %43
43: ; preds = %34, %41
%44 = call i32 @fclose(i32* %33)
%45 = call i32* @fgets(i8* %13, i32 1000, i32* %24)
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %28
47: ; preds = %43, %2
%48 = call i32 @fclose(i32* %25)
%49 = call i32 @fclose(i32* %24)
ret i32 0
}