#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 */

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ putchar(char);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(void) {
  int res;
  srand(12345);
  for (int attempt = 0; attempt < 3; attempt++) {
    for (int position = 0; position < 5000; position++) {
      putchar("01"[rand() % 2]);
    }
    putchar('\n');
    fflush(stdout);
    scanf("%d", &res);
    fprintf(stderr, "%5d", res);
  }
  fprintf(stderr, "\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3039,%edi
call   1040 <srand@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    121e <main+0xbe>
movl   $0x0,-0x10(%rbp)
cmpl   $0x1388,-0x10(%rbp)
jge    11ce <main+0x6e>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq %edx,%rcx
lea    0xe49(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1191 <main+0x31>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xe16(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1180 <main+0x20>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x3039,%edi
call   1040 <srand@plt>
mov    $0x1388,%ebp
lea    0xe83(%rip),%rbx
nopl   (%rax)
xor    %eax,%eax
call   1080 <rand@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
cltq
movsbl (%rax,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1180 <main+0x20>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2e24(%rip),%r15
mov    (%r15),%edi
call   1060 <fflush@plt>
lea    0xe40(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x2e0c(%rip),%r14
mov    (%r14),%edi
mov    0x4(%rsp),%edx
lea    0xe24(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1388,%ebp
xchg   %ax,%ax
xor    %eax,%eax
call   1080 <rand@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
cltq
movsbl (%rax,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    11f0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%r15),%edi
call   1060 <fflush@plt>
lea    0xdd7(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    (%r14),%edi
mov    0x4(%rsp),%edx
lea    0xdc2(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1388,%ebp
xor    %eax,%eax
call   1080 <rand@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
cltq
movsbl (%rax,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1250 <main+0xf0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%r15),%edi
call   1060 <fflush@plt>
lea    0xd77(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    (%r14),%edi
mov    0x4(%rsp),%edx
lea    0xd62(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edi
lea    0xd55(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"01\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [4 x i8] c"%5d\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @srand(i32 12345)
store i32 0, i32* %3
br label %6
6: ; preds = %31, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %34
9: ; preds = %6
store i32 0, i32* %4
br label %10
10: ; preds = %20, %9
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 5000
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [3 x i8], [3 x i8]* @.str, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @putchar(i8 signext %18)
br label %20
20: ; preds = %13
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %10
23: ; preds = %10
%24 = call i32 @putchar(i8 signext 10)
%25 = load i32, i32* @stdout
%26 = call i32 @fflush(i32 %25)
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%28 = load i32, i32* @stderr
%29 = load i32, i32* %2
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %23
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %6
34: ; preds = %6
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"01\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [4 x i8] c"%5d\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @srand(i32 12345)
br label %50
4: ; preds = %50
%5 = call i32 @putchar(i8 signext 10)
%6 = load i32, i32* @stdout
%7 = call i32 @fflush(i32 %6)
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = load i32, i32* @stderr
%10 = load i32, i32* %1
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %12, %4
%13 = phi i32 [ 0, %4 ], [ %20, %12 ]
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [3 x i8], [3 x i8]* @.str, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @putchar(i8 signext %18)
%20 = add nuw nsw i32 %13, 1
%21 = icmp eq i32 %20, 5000
br i1 %21, label %22, label %12
22: ; preds = %12
%23 = call i32 @putchar(i8 signext 10)
%24 = load i32, i32* @stdout
%25 = call i32 @fflush(i32 %24)
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%27 = load i32, i32* @stderr
%28 = load i32, i32* %1
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %30, %22
%31 = phi i32 [ 0, %22 ], [ %38, %30 ]
%32 = call i32 (...) @rand()
%33 = srem i32 %32, 2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [3 x i8], [3 x i8]* @.str, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @putchar(i8 signext %36)
%38 = add nuw nsw i32 %31, 1
%39 = icmp eq i32 %38, 5000
br i1 %39, label %40, label %30
40: ; preds = %30
%41 = call i32 @putchar(i8 signext 10)
%42 = load i32, i32* @stdout
%43 = call i32 @fflush(i32 %42)
%44 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%45 = load i32, i32* @stderr
%46 = load i32, i32* %1
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
50: ; preds = %0, %50
%51 = phi i32 [ 0, %0 ], [ %58, %50 ]
%52 = call i32 (...) @rand()
%53 = srem i32 %52, 2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [3 x i8], [3 x i8]* @.str, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = call i32 @putchar(i8 signext %56)
%58 = add nuw nsw i32 %51, 1
%59 = icmp eq i32 %58, 5000
br i1 %59, label %4, label %50
}