#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*/ fanout_debug(int /*<<< orphan*/, char *, char *);
int read(int, char *, int);
void clear_socket_buffer(int sock) {
  char buffer[1025];
  for (;;) {
    int res = read(sock, buffer, 1024);
    if (res < 0) {
      fanout_debug(0, "%s\n", "failed clearing socket buffer");
      break;
    }
    if (!res)
      break;
  }
}


x86 assembly (clang, -O0):
<clear_socket_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1030 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    116f <clear_socket_buffer+0x4f>
xor    %edi,%edi
lea    0xea2(%rip),%rsi
lea    0xe9f(%rip),%rdx
call   1040 <fanout_debug@plt>
jmp    1186 <clear_socket_buffer+0x66>
cmpl   $0x0,-0x414(%rbp)
jne    1181 <clear_socket_buffer+0x61>
jmp    1186 <clear_socket_buffer+0x66>
jmp    112e <clear_socket_buffer+0xe>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear_socket_buffer>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
nop
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1030 <read@plt>
test   %eax,%eax
js     1150 <clear_socket_buffer+0x30>
jne    1130 <clear_socket_buffer+0x10>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret
lea    0xea9(%rip),%rsi
lea    0xea6(%rip),%rdx
xor    %edi,%edi
add    $0x408,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fanout_debug@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [30 x i8] c"failed clearing socket buffer\00"
define void @clear_socket_buffer(i32 %0) {
%2 = alloca i32
%3 = alloca [1025 x i8]
%4 = alloca i32
store i32 %0, i32* %2
br label %5
5: ; preds = %17, %1
%6 = load i32, i32* %2
%7 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 1024)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = call i32 @fanout_debug(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %18
13: ; preds = %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %13
br label %18
17: ; preds = %13
br label %5
18: ; preds = %16, %11
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [30 x i8] c"failed clearing socket buffer\00"
define void @clear_socket_buffer(i32 %0) {
%2 = alloca [1025 x i8]
%3 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %9, %1
%5 = call i32 @read(i32 %0, i8* %3, i32 1024)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @fanout_debug(i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %11
9: ; preds = %4
%10 = icmp eq i32 %5, 0
br i1 %10, label %11, label %4
11: ; preds = %9, %7
ret void
}