#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*/ uint8_t;
typedef scalar_t__ int32_t;

/* Variables and functions */
scalar_t__ printf(char *, scalar_t__);
scalar_t__ recv_one_byte(int /*<<< orphan*/ *, scalar_t__);
void flush_recv_buf(int32_t timeout) {
  uint8_t c;
  int32_t count = 0;
  while (recv_one_byte(&c, timeout) == 0)
    count++;
  count > 0 ? printf("flushed %d bytes\n", count) : count;
}


x86 assembly (clang, -O0):
<flush_recv_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdi
call   1030 <recv_one_byte@plt>
cmp    $0x0,%rax
jne    115c <flush_recv_buf+0x3c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1134 <flush_recv_buf+0x14>
cmpq   $0x0,-0x18(%rbp)
jle    117c <flush_recv_buf+0x5c>
mov    -0x18(%rbp),%rsi
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
jmp    1180 <flush_recv_buf+0x60>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flush_recv_buf>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    $0x1,%ebx
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <recv_one_byte@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
je     1140 <flush_recv_buf+0x20>
test   %rbx,%rbx
je     116b <flush_recv_buf+0x4b>
neg    %rbx
lea    0xe9d(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"flushed %d bytes\0A\00"
define void @flush_recv_buf(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
store i64 %0, i64* %2
store i64 0, i64* %4
br label %5
5: ; preds = %9, %1
%6 = load i64, i64* %2
%7 = call i64 @recv_one_byte(i32* %3, i64 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i64, i64* %4
%11 = add nsw i64 %10, 1
store i64 %11, i64* %4
br label %5
12: ; preds = %5
%13 = load i64, i64* %4
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i64, i64* %4
%17 = call i64 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %16)
br label %20
18: ; preds = %12
%19 = load i64, i64* %4
br label %20
20: ; preds = %18, %15
%21 = phi i64 [ %17, %15 ], [ %19, %18 ]
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"flushed %d bytes\0A\00"
define void @flush_recv_buf(i64 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ 0, %1 ], [ %8, %4 ]
%6 = call i64 @recv_one_byte(i32* %2, i64 %0)
%7 = icmp eq i64 %6, 0
%8 = add nuw nsw i64 %5, 1
br i1 %7, label %4, label %9
9: ; preds = %4
%10 = icmp eq i64 %5, 0
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = call i64 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %5)
br label %13
13: ; preds = %9, %11
ret void
}