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

/* Variables and functions */
scalar_t__ EAGAIN;
int /*<<< orphan*/ MSG_DONTWAIT;
scalar_t__ errno;
int /*<<< orphan*/ error(int, scalar_t__, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int recv_udp(int fd) {
  static char buf[100];
  int ret, count = 0;
  while (1) {
    ret = recv(fd, buf, sizeof(buf), MSG_DONTWAIT);
    if (ret == -1 && errno == EAGAIN)
      break;
    if (ret == -1)
      error(1, errno, "recv r");
    fprintf(stderr, "udp: len=%u\n", ret);
    count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<recv_udp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e84(%rip),%rax
mov    (%rax),%ecx
lea    0x2efb(%rip),%rsi
mov    $0x64,%edx
call   1030 <recv@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    118b <recv_udp+0x5b>
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%rax
jne    118b <recv_udp+0x5b>
jmp    11d6 <recv_udp+0xa6>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b0 <recv_udp+0x80>
mov    0x2e3c(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
lea    0xe55(%rip),%rdx
call   1050 <error@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe44(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1142 <recv_udp+0x12>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_udp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r13d
xor    %ebx,%ebx
lea    0x2f09(%rip),%r14
mov    0x2e92(%rip),%r15
lea    0xeb2(%rip),%r12
jmp    1170 <recv_udp+0x40>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <fprintf@plt>
add    $0x1,%ebx
mov    0x2e59(%rip),%rax
mov    (%rax),%ecx
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1030 <recv@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1160 <recv_udp+0x30>
mov    0x2e41(%rip),%rax
mov    (%rax),%rsi
mov    0x2e1f(%rip),%rax
cmp    (%rax),%rsi
je     11b9 <recv_udp+0x89>
mov    $0x1,%edi
lea    0xe4e(%rip),%rdx
call   1050 <error@plt>
jmp    1160 <recv_udp+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@recv_udp.buf = internal global [100 x i8] zeroinitializer
@MSG_DONTWAIT = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [7 x i8] c"recv r\00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"udp: len=%u\0A\00"
define i32 @recv_udp(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %5
5: ; preds = %1, %22
%6 = load i32, i32* %2
%7 = load i32, i32* @MSG_DONTWAIT
%8 = call i32 @recv(i32 %6, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @recv_udp.buf, i64 0, i64 0), i32 100, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = load i64, i64* @errno
%13 = load i64, i64* @EAGAIN
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
br label %28
16: ; preds = %11, %5
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i64, i64* @errno
%21 = call i32 @error(i32 1, i64 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* @stderr
%24 = load i32, i32* %3
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %5
28: ; preds = %15
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@recv_udp.buf = internal global [100 x i8] zeroinitializer
@MSG_DONTWAIT = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [7 x i8] c"recv r\00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"udp: len=%u\0A\00"
define i32 @recv_udp(i32 %0) {
br label %2
2: ; preds = %13, %1
%3 = phi i32 [ 0, %1 ], [ %16, %13 ]
%4 = load i32, i32* @MSG_DONTWAIT
%5 = tail call i32 @recv(i32 %0, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @recv_udp.buf, i64 0, i64 0), i32 100, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i64, i64* @errno
%9 = load i64, i64* @EAGAIN
%10 = icmp eq i64 %8, %9
br i1 %10, label %17, label %11
11: ; preds = %7
%12 = tail call i32 @error(i32 1, i64 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %2, %11
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%16 = add nuw nsw i32 %3, 1
br label %2
17: ; preds = %7
ret i32 %3
}