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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fsync(int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char next_letter();
int rand();
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ system(char *);
void winno_file(int difficulty, char *infile) {
  FILE *output = stdout;
  FILE *input;
  int closein = 0;
  unsigned char next_msg_char = 0;
  unsigned char next_chaff = 0;
  if (strcmp(infile, "stdin") != 0) {
    input = fopen(infile, "r");
    closein = 1;
  } else
    input = stdin;
  while (!feof(input) && !ferror(input)) {
    if ((rand() % (difficulty + 1)) != 0) {
      next_chaff = next_letter();
      fread(&next_msg_char, sizeof(next_msg_char), 1, input);
    } else {
      fread(&next_msg_char, sizeof(next_msg_char), 1, input);
      fwrite(&next_msg_char, sizeof(next_msg_char), 1, output);
    }
  }
  if (closein)
    fclose(input);
  fsync(fileno(output));
  system("sync; sync;");
  return;
}


x86 assembly (clang, -O0):
<winno_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movb   $0x0,-0x25(%rbp)
movb   $0x0,-0x26(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1226 <winno_file+0x66>
mov    -0x10(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    1234 <winno_file+0x74>
mov    0x2dbb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1239 <winno_file+0x79>
mov    -0x20(%rbp),%rdi
call   1090 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x27(%rbp)
jne    1266 <winno_file+0xa6>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x27(%rbp)
mov    -0x27(%rbp),%al
test   $0x1,%al
jne    1276 <winno_file+0xb6>
jmp    12df <winno_file+0x11f>
mov    $0x0,%al
call   10e0 <rand@plt>
mov    -0x4(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12b2 <winno_file+0xf2>
mov    $0x0,%al
call   1050 <next_letter@plt>
mov    %al,-0x26(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x25(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
jmp    12da <winno_file+0x11a>
mov    -0x20(%rbp),%rcx
lea    -0x25(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    -0x18(%rbp),%rcx
lea    -0x25(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10d0 <fwrite@plt>
jmp    1239 <winno_file+0x79>
cmpl   $0x0,-0x24(%rbp)
je     12f2 <winno_file+0x132>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <fileno@plt>
mov    %eax,%edi
call   10b0 <fsync@plt>
lea    0xcff(%rip),%rdi
call   1070 <system@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<winno_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e00(%rip),%rax
mov    (%rax),%r15
movb   $0x0,0xf(%rsp)
lea    0xe19(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
mov    %rax,%r14
test   %rax,%rax
je     120b <winno_file+0x4b>
lea    0xe08(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
mov    %rax,%rbx
jmp    1215 <winno_file+0x55>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     1255 <winno_file+0x95>
test   %r14,%r14
je     122e <winno_file+0x6e>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   10b0 <fileno@plt>
mov    %eax,%edi
call   10c0 <fsync@plt>
lea    0xdc4(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <system@plt>
add    $0x1,%ebp
lea    0xf(%rsp),%r12
jmp    128e <winno_file+0xce>
nop
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
movsbl 0xf(%rsp),%edi
mov    %r15,%rsi
call   1080 <fputc@plt>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1221 <winno_file+0x61>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    1221 <winno_file+0x61>
xor    %eax,%eax
call   10e0 <rand@plt>
cltd
idiv   %ebp
test   %edx,%edx
je     1260 <winno_file+0xa0>
xor    %eax,%eax
call   1050 <next_letter@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
jmp    1282 <winno_file+0xc2>

LLVM IR (-O0):
@stdout = global i32* null
@.str = [6 x i8] c"stdin\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.2 = [12 x i8] c"sync; sync;\00"
define void @winno_file(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = load i32*, i32** @stdout
store i32* %10, i32** %5
store i32 0, i32* %7
store i8 0, i8* %8
store i8 0, i8* %9
%11 = load i8*, i8** %4
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %6
store i32 1, i32* %7
br label %19
17: ; preds = %2
%18 = load i32*, i32** @stdin
store i32* %18, i32** %6
br label %19
19: ; preds = %17, %14
br label %20
20: ; preds = %46, %19
%21 = load i32*, i32** %6
%22 = call i32 @feof(i32* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %20
%25 = load i32*, i32** %6
%26 = call i32 @ferror(i32* %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br label %29
29: ; preds = %24, %20
%30 = phi i1 [ false, %20 ], [ %28, %24 ]
br i1 %30, label %31, label %47
31: ; preds = %29
%32 = call i32 (...) @rand()
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
%35 = srem i32 %32, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = call zeroext i8 (...) @next_letter()
store i8 %38, i8* %9
%39 = load i32*, i32** %6
%40 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %39)
br label %46
41: ; preds = %31
%42 = load i32*, i32** %6
%43 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %42)
%44 = load i32*, i32** %5
%45 = call i32 @fwrite(i8* %8, i32 1, i32 1, i32* %44)
br label %46
46: ; preds = %41, %37
br label %20
47: ; preds = %29
%48 = load i32, i32* %7
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i32*, i32** %6
%52 = call i32 @fclose(i32* %51)
br label %53
53: ; preds = %50, %47
%54 = load i32*, i32** %5
%55 = call i32 @fileno(i32* %54)
%56 = call i32 @fsync(i32 %55)
%57 = call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@stdout = global i32* null
@.str = [6 x i8] c"stdin\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32* null
@.str.2 = [12 x i8] c"sync; sync;\00"
define void @winno_file(i32 %0, i8* %1) {
%3 = alloca i8
%4 = load i32*, i32** @stdout
store i8 0, i8* %3
%5 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %11
9: ; preds = %2
%10 = load i32*, i32** @stdin
br label %11
11: ; preds = %9, %7
%12 = phi i32* [ %8, %7 ], [ %10, %9 ]
%13 = tail call i32 @feof(i32* %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %35
15: ; preds = %11
%16 = add nsw i32 %0, 1
br label %17
17: ; preds = %15, %32
%18 = tail call i32 @ferror(i32* %12)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %17
%21 = tail call i32 (...) @rand()
%22 = srem i32 %21, %16
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = tail call zeroext i8 (...) @next_letter()
%26 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %12)
br label %32
27: ; preds = %20
%28 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %12)
%29 = load i8, i8* %3
%30 = sext i8 %29 to i32
%31 = tail call i32 @fputc(i32 %30, i32* %4)
br label %32
32: ; preds = %27, %24
%33 = tail call i32 @feof(i32* %12)
%34 = icmp eq i32 %33, 0
br i1 %34, label %17, label %35
35: ; preds = %17, %32, %11
br i1 %6, label %38, label %36
36: ; preds = %35
%37 = tail call i32 @fclose(i32* %12)
br label %38
38: ; preds = %36, %35
%39 = tail call i32 @fileno(i32* %4)
%40 = tail call i32 @fsync(i32 %39)
%41 = tail call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
ret void
}