#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*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy2(char *, char *);
int strlen2(char *);
int main() {
  int wordLen = 2;
  char line[256];
  char linec[256];
  FILE *ifPtr = fopen("sowpods.txt", "r");
  FILE *ofPtr = fopen("wordlist.txt", "w");
  if (ifPtr == NULL)
    printf("\"sowpods.txt\" could not be opened.\n");
  else if (ofPtr == NULL)
    printf("\"wordlist.txt\" could not be opened.\n");
  else {
    while (fgets(line, sizeof line, ifPtr) != NULL) {
      if (strlen2(line) == wordLen + 1) {
        strcpy2(linec, line);
        fprintf(ofPtr, "%s\n", linec);
      }
    }
    fclose(ifPtr);
    fclose(ofPtr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
lea    0xe70(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x218(%rbp)
lea    0xe64(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    11dc <main+0x6c>
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
jmp    128b <main+0x11b>
cmpq   $0x0,-0x220(%rbp)
jne    11fb <main+0x8b>
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
jmp    1286 <main+0x116>
jmp    1200 <main+0x90>
lea    -0x110(%rbp),%rdi
mov    -0x218(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     126e <main+0xfe>
lea    -0x110(%rbp),%rdi
call   1070 <strlen2@plt>
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    1269 <main+0xf9>
lea    -0x210(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1090 <strcpy2@plt>
mov    -0x220(%rbp),%rdi
lea    -0x210(%rbp),%rdx
lea    0xe02(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1200 <main+0x90>
mov    -0x218(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x220(%rbp),%rdi
call   1030 <fclose@plt>
jmp    128b <main+0x11b>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200,%rsp
lea    0xe79(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
lea    0xe71(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
test   %r15,%r15
je     123f <main+0xcf>
mov    %rax,%r14
test   %rax,%rax
je     1248 <main+0xd8>
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     122d <main+0xbd>
mov    %rsp,%rbx
lea    0x100(%rsp),%r12
lea    0xe38(%rip),%r13
jmp    1205 <main+0x95>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     122d <main+0xbd>
mov    %rbx,%rdi
call   1070 <strlen2@plt>
cmp    $0x3,%eax
jne    11f0 <main+0x80>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <strcpy2@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1060 <fprintf@plt>
jmp    11f0 <main+0x80>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    1254 <main+0xe4>
lea    0xdff(%rip),%rdi
jmp    124f <main+0xdf>
lea    0xdd2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"sowpods.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"wordlist.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [36 x i8] c"\22sowpods.txt\22 could not be opened.\0A\00"
@.str.5 = [37 x i8] c"\22wordlist.txt\22 could not be opened.\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca i32*
%6 = alloca i32*
store i32 0, i32* %1
store i32 2, i32* %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
br label %44
13: ; preds = %0
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %43
18: ; preds = %13
br label %19
19: ; preds = %37, %18
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%21 = load i32*, i32** %5
%22 = call i32* @fgets(i8* %20, i32 256, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %38
24: ; preds = %19
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%26 = call i32 @strlen2(i8* %25)
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
%29 = icmp eq i32 %26, %28
br i1 %29, label %30, label %37
30: ; preds = %24
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%33 = call i32 @strcpy2(i8* %31, i8* %32)
%34 = load i32*, i32** %6
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%36 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %30, %24
br label %19
38: ; preds = %19
%39 = load i32*, i32** %5
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %6
%42 = call i32 @fclose(i32* %41)
br label %43
43: ; preds = %38, %16
br label %44
44: ; preds = %43, %11
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"sowpods.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"wordlist.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@str = [36 x i8] c"\22wordlist.txt\22 could not be opened.\00"
@str.7 = [35 x i8] c"\22sowpods.txt\22 could not be opened.\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i32* %5, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.7, i64 0, i64 0))
br label %29
10: ; preds = %0
%11 = icmp eq i32* %6, null
br i1 %11, label %15, label %12
12: ; preds = %10
%13 = call i32* @fgets(i8* %3, i32 256, i32* %5)
%14 = icmp eq i32* %13, null
br i1 %14, label %26, label %17
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %29
17: ; preds = %12, %23
%18 = call i32 @strlen2(i8* %3)
%19 = icmp eq i32 %18, 3
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @strcpy2(i8* %4, i8* %3)
%22 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %4)
br label %23
23: ; preds = %20, %17
%24 = call i32* @fgets(i8* %3, i32 256, i32* %5)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %17
26: ; preds = %23, %12
%27 = call i32 @fclose(i32* %5)
%28 = call i32 @fclose(i32* %6)
br label %29
29: ; preds = %15, %26, %8
ret i32 0
}