#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int c, count, j;
  char cout, cin;
  FILE *in, *log;
  if ((in = fopen(argv[1], "r")) == (FILE *)NULL) {
    fprintf(stderr, "Can't open '%s'\n", argv[1]);
    exit(1);
  }
  if ((log = fopen("/tmp/dl.log", "w")) == (FILE *)NULL) {
    fprintf(stderr, "Can't open log file\n");
    exit(1);
  }
  fprintf(stderr, "Downloading '%s'\n", argv[1]);
  count = 0;
  j = 0;
  write(1, ">", 1);
  while ((c = fgetc(in)) != EOF) {
    cout = c;
    write(1, &cout, 1);
    if (++j == 63) {
      read(0, &cin, 1);
      if (cin != cout) {
        fprintf(stderr, "Sync problem - in: %x, out: %x, byte: %x\n", cin, cout,
                count);
        fprintf(log, "Sync problem - in: %x, out: %x, byte: %x\n", cin, cout,
                count);
        fflush(log);
        break;
      }
      j = 0;
    }
    count++;
    if ((count % 256) == 255)
      fprintf(stderr, "%08X\n", count);
  }
  sleep(2);
  write(1, ":", 1);
  fclose(log);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11f1 <main+0x61>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe1b(%rip),%rdi
lea    0xe20(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1233 <main+0xa3>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x1,%edx
lea    0xddc(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d62(%rip),%rcx
cmp    (%rcx),%eax
je     136d <main+0x1dd>
mov    -0x14(%rbp),%eax
mov    %al,-0x1d(%rbp)
mov    $0x1,%edx
lea    -0x1d(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x3f,%eax
jne    132e <main+0x19e>
xor    %edi,%edi
lea    -0x1e(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl -0x1e(%rbp),%eax
movsbl -0x1d(%rbp),%ecx
cmp    %ecx,%eax
je     1327 <main+0x197>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
movsbl -0x1e(%rbp),%edx
movsbl -0x1d(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xd58(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    %eax,%edi
movsbl -0x1e(%rbp),%edx
movsbl -0x1d(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xd38(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1080 <fflush@plt>
jmp    136d <main+0x1dd>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
cmp    $0xff,%edx
jne    1368 <main+0x1d8>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xd13(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1273 <main+0xe3>
mov    $0x2,%edi
call   10b0 <sleep@plt>
mov    $0x1,%edx
lea    0xcf7(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe54(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    11db <main+0x4b>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xe38(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rax,%rbx
lea    0xe2e(%rip),%rdi
lea    0xe33(%rip),%rsi
call   1090 <fopen@plt>
mov    0x2de0(%rip),%rcx
mov    (%rcx),%edi
test   %rax,%rax
jne    1217 <main+0x87>
lea    0xe1b(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rax,0x10(%rsp)
mov    0x8(%rbp),%rdx
lea    0xe0f(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe13(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r14d
mov    0x2d92(%rip),%rax
cmp    (%rax),%r14d
je     1338 <main+0x1a8>
lea    0xf(%rsp),%r15
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    128b <main+0xfb>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r14d
mov    0x2d66(%rip),%rax
cmp    (%rax),%r14d
je     1338 <main+0x1a8>
mov    %r14b,0xf(%rsp)
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x1,%r13d
cmp    $0x3f,%r13d
jne    12cb <main+0x13b>
xor    %r13d,%r13d
xor    %edi,%edi
lea    0xe(%rsp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl 0xe(%rsp),%r12d
cmp    %r14b,%r12b
jne    12ef <main+0x15f>
add    $0x1,%ebp
cmp    $0xff,%bpl
jne    1270 <main+0xe0>
mov    0x2cfd(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1270 <main+0xe0>
movsbl %r14b,%r15d
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    0xd47(%rip),%r14
mov    %r14,%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x10(%rsp),%rbx
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    $0x2,%edi
call   10b0 <sleep@plt>
lea    0xd31(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    0x10(%rsp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"Can't open '%s'\0A\00"
@.str.2 = [12 x i8] c"/tmp/dl.log\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"Can't open log file\0A\00"
@.str.5 = [18 x i8] c"Downloading '%s'\0A\00"
@.str.6 = [2 x i8] c">\00"
@EOF = global i32 0
@.str.7 = [42 x i8] c"Sync problem - in: %x, out: %x, byte: %x\0A\00"
@.str.8 = [6 x i8] c"%08X\0A\00"
@.str.9 = [2 x i8] c":\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8
%11 = alloca i32*
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %11
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 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* %26, i32** %12
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %36)
store i32 0, i32* %7
store i32 0, i32* %8
%38 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1)
br label %39
39: ; preds = %87, %32
%40 = load i32*, i32** %11
%41 = call i32 @fgetc(i32* %40)
store i32 %41, i32* %6
%42 = load i32, i32* @EOF
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %88
44: ; preds = %39
%45 = load i32, i32* %6
%46 = trunc i32 %45 to i8
store i8 %46, i8* %9
%47 = call i32 @write(i32 1, i8* %9, i32 1)
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
%50 = icmp eq i32 %49, 63
br i1 %50, label %51, label %77
51: ; preds = %44
%52 = call i32 @read(i32 0, i8* %10, i32 1)
%53 = load i8, i8* %10
%54 = sext i8 %53 to i32
%55 = load i8, i8* %9
%56 = sext i8 %55 to i32
%57 = icmp ne i32 %54, %56
br i1 %57, label %58, label %76
58: ; preds = %51
%59 = load i32, i32* @stderr
%60 = load i8, i8* %10
%61 = sext i8 %60 to i32
%62 = load i8, i8* %9
%63 = sext i8 %62 to i32
%64 = load i32, i32* %7
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %61, i32 %63, i32 %64)
%66 = load i32*, i32** %12
%67 = ptrtoint i32* %66 to i32
%68 = load i8, i8* %10
%69 = sext i8 %68 to i32
%70 = load i8, i8* %9
%71 = sext i8 %70 to i32
%72 = load i32, i32* %7
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %69, i32 %71, i32 %72)
%74 = load i32*, i32** %12
%75 = call i32 @fflush(i32* %74)
br label %88
76: ; preds = %51
store i32 0, i32* %8
br label %77
77: ; preds = %76, %44
%78 = load i32, i32* %7
%79 = add nsw i32 %78, 1
store i32 %79, i32* %7
%80 = load i32, i32* %7
%81 = srem i32 %80, 256
%82 = icmp eq i32 %81, 255
br i1 %82, label %83, label %87
83: ; preds = %77
%84 = load i32, i32* @stderr
%85 = load i32, i32* %7
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %85)
br label %87
87: ; preds = %83, %77
br label %39
88: ; preds = %58, %39
%89 = call i32 @sleep(i32 2)
%90 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 1)
%91 = load i32*, i32** %12
%92 = call i32 @fclose(i32* %91)
%93 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"Can't open '%s'\0A\00"
@.str.2 = [12 x i8] c"/tmp/dl.log\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"Can't open log file\0A\00"
@.str.5 = [18 x i8] c"Downloading '%s'\0A\00"
@.str.6 = [2 x i8] c">\00"
@EOF = global i32 0
@.str.7 = [42 x i8] c"Sync problem - in: %x, out: %x, byte: %x\0A\00"
@.str.8 = [6 x i8] c"%08X\0A\00"
@.str.9 = [2 x i8] c":\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca i8
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %5
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i32* %15, null
%17 = load i32, i32* @stderr
br i1 %16, label %18, label %21
18: ; preds = %14
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %14
%22 = load i8*, i8** %5
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%24 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1)
%25 = tail call i32 @fgetc(i32* %7)
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %62, label %28
28: ; preds = %21, %58
%29 = phi i32 [ %59, %58 ], [ %25, %21 ]
%30 = phi i32 [ %52, %58 ], [ 0, %21 ]
%31 = phi i32 [ %51, %58 ], [ 0, %21 ]
%32 = trunc i32 %29 to i8
store i8 %32, i8* %3
%33 = call i32 @write(i32 1, i8* %3, i32 1)
%34 = add nsw i32 %31, 1
%35 = icmp eq i32 %34, 63
br i1 %35, label %36, label %50
36: ; preds = %28
%37 = call i32 @read(i32 0, i8* %4, i32 1)
%38 = load i8, i8* %4
%39 = icmp eq i8 %38, %32
br i1 %39, label %50, label %40
40: ; preds = %36
%41 = shl i32 %29, 24
%42 = ashr exact i32 %41, 24
%43 = sext i8 %38 to i32
%44 = load i32, i32* @stderr
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %43, i32 %42, i32 %30)
%46 = ptrtoint i32* %15 to i64
%47 = trunc i64 %46 to i32
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %43, i32 %42, i32 %30)
%49 = tail call i32 @fflush(i32* %15)
br label %62
50: ; preds = %36, %28
%51 = phi i32 [ %34, %28 ], [ 0, %36 ]
%52 = add nuw nsw i32 %30, 1
%53 = and i32 %52, 255
%54 = icmp eq i32 %53, 255
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = tail call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %52)
br label %58
58: ; preds = %55, %50
%59 = tail call i32 @fgetc(i32* %7)
%60 = load i32, i32* @EOF
%61 = icmp eq i32 %59, %60
br i1 %61, label %62, label %28
62: ; preds = %58, %21, %40
%63 = tail call i32 @sleep(i32 2)
%64 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 1)
%65 = tail call i32 @fclose(i32* %15)
%66 = tail call i32 @exit(i32 0)
unreachable
}