#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 */
scalar_t__ read(int, void *, int);
int /*<<< orphan*/ write(int, void *, int);
void readAff(int s, char C) {
  char b[2];
  int ok = 0;
  if (read(s, (void *)b, 1) <= 0)
    return;
  if (*b == C)
    ok = 1;
  while (*b != (char)3) {
    if (read(s, (void *)b, 1) <= 0)
      break;
    else {
      if (ok)
        write(1, (void *)b, 1);
    }
  }
}


x86 assembly (clang, -O0):
<readAff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x7(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jg     1158 <readAff+0x38>
jmp    11c5 <readAff+0xa5>
movsbl -0x7(%rbp),%eax
movsbl -0x5(%rbp),%ecx
cmp    %ecx,%eax
jne    116f <readAff+0x4f>
movl   $0x1,-0xc(%rbp)
jmp    1174 <readAff+0x54>
movsbl -0x7(%rbp),%eax
cmp    $0x3,%eax
je     11c5 <readAff+0xa5>
mov    -0x4(%rbp),%edi
lea    -0x7(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jg     11a1 <readAff+0x81>
jmp    11c5 <readAff+0xa5>
cmpl   $0x0,-0xc(%rbp)
je     11bb <readAff+0x9b>
lea    -0x7(%rbp),%rsi
mov    $0x1,%edx
mov    %edx,%edi
call   1030 <write@plt>
jmp    11c0 <readAff+0xa0>
jmp    1174 <readAff+0x54>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readAff>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%ebp
lea    0x6(%rsp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    1149 <readAff+0x29>
mov    0x6(%rsp),%bl
cmp    $0x3,%bl
jne    1154 <readAff+0x34>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x6(%rsp),%r14
jmp    1167 <readAff+0x47>
nopl   0x0(%rax,%rax,1)
cmpb   $0x3,0x6(%rsp)
je     1149 <readAff+0x29>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    1149 <readAff+0x29>
cmp    %r15b,%bl
jne    1160 <readAff+0x40>
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1160 <readAff+0x40>

LLVM IR (-O0):
define void @readAff(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca [2 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i8 %1, i8* %4
store i32 0, i32* %6
%7 = load i32, i32* %3
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%9 = call i64 @read(i32 %7, i8* %8, i32 1)
%10 = icmp sle i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
br label %40
12: ; preds = %2
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %15, %17
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 1, i32* %6
br label %20
20: ; preds = %19, %12
br label %21
21: ; preds = %39, %20
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 3
br i1 %25, label %26, label %40
26: ; preds = %21
%27 = load i32, i32* %3
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%29 = call i64 @read(i32 %27, i8* %28, i32 1)
%30 = icmp sle i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
br label %40
32: ; preds = %26
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%37 = call i32 @write(i32 1, i8* %36, i32 1)
br label %38
38: ; preds = %35, %32
br label %39
39: ; preds = %38
br label %21
40: ; preds = %11, %31, %21
ret void
}

LLVM IR (-O2):
define void @readAff(i32 %0, i8 signext %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = call i64 @read(i32 %0, i8* %4, i32 1)
%6 = icmp slt i64 %5, 1
br i1 %6, label %20, label %7
7: ; preds = %2
%8 = load i8, i8* %4
%9 = icmp eq i8 %8, %1
%10 = icmp eq i8 %8, 3
br i1 %10, label %20, label %11
11: ; preds = %7, %17
%12 = call i64 @read(i32 %0, i8* %4, i32 1)
%13 = icmp slt i64 %12, 1
br i1 %13, label %20, label %14
14: ; preds = %11
br i1 %9, label %15, label %17
15: ; preds = %14
%16 = call i32 @write(i32 1, i8* %4, i32 1)
br label %17
17: ; preds = %14, %15
%18 = load i8, i8* %4
%19 = icmp eq i8 %18, 3
br i1 %19, label %20, label %11
20: ; preds = %11, %17, %7, %2
ret void
}