#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 uint8_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int read(int, int *, int);
void discard_input(int fd) {
  uint8_t buffer[64];
  int res, i;
  do {
    res = read(fd, buffer, sizeof(buffer));
    if (res > 0) {
      printf("Recv[%d]:", res);
      for (i = 0; i < res; i++)
        printf("%02x ", buffer[i]);
      printf("\n");
    }
  } while (res > 0);
}


x86 assembly (clang, -O0):
<discard_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1040 <read@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jle    11c3 <discard_input+0xa3>
mov    -0x114(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x118(%rbp)
mov    -0x118(%rbp),%eax
cmp    -0x114(%rbp),%eax
jge    11b5 <discard_input+0x95>
movslq -0x118(%rbp),%rax
mov    -0x110(%rbp,%rax,4),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    1173 <discard_input+0x53>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c8 <discard_input+0xa8>
cmpl   $0x0,-0x114(%rbp)
jg     112e <discard_input+0xe>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<discard_input>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %edi,%r12d
mov    %rsp,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11b6 <discard_input+0x86>
mov    %eax,%ebp
lea    0xea2(%rip),%r14
lea    0xea5(%rip),%r13
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%ebp
xor    %ebx,%ebx
mov    (%rsp,%rbx,4),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <discard_input+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1170 <discard_input+0x40>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Recv[%d]:\00"
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @discard_input(i32 %0) {
%2 = alloca i32
%3 = alloca [64 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
br label %6
6: ; preds = %31, %1
%7 = load i32, i32* %2
%8 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 0
%9 = call i32 @read(i32 %7, i32* %8, i32 256)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %30
12: ; preds = %6
%13 = load i32, i32* %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 0, i32* %5
br label %15
15: ; preds = %25, %12
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %19
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %15
28: ; preds = %15
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %6
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = icmp sgt i32 %32, 0
br i1 %33, label %6, label %34
34: ; preds = %31
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"Recv[%d]:\00"
@.str.1 = [6 x i8] c"%02x \00"
define void @discard_input(i32 %0) {
%2 = alloca [64 x i32]
%3 = bitcast [64 x i32]* %2 to i8*
%4 = getelementptr inbounds [64 x i32], [64 x i32]* %2, i64 0, i64 0
%5 = call i32 @read(i32 %0, i32* %4, i32 256)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %1, %18
%8 = phi i32 [ %20, %18 ], [ %5, %1 ]
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = zext i32 %8 to i64
br label %11
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %16, %11 ]
%13 = getelementptr inbounds [64 x i32], [64 x i32]* %2, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, %10
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = tail call i32 @putchar(i32 10)
%20 = call i32 @read(i32 %0, i32* %4, i32 256)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %7, label %22
22: ; preds = %18, %1
ret void
}