#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 */
struct msghdr {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ errno;
int sendmsg(int, struct msghdr const *, int);
int /*<<< orphan*/ task_yield();
ssize_t sys_sendmsg(int sockfd, const struct msghdr *msg, int flags) {
  ssize_t ret;
RETRY:
  ret = sendmsg(sockfd, msg, flags);
  if (ret == -1 && errno == EAGAIN) {
    task_yield();
    goto RETRY;
  }
  return ret;
}


x86 assembly (clang, -O0):
<sys_sendmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <sendmsg@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1174 <sys_sendmsg+0x54>
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
jne    1174 <sys_sendmsg+0x54>
mov    $0x0,%al
call   1040 <task_yield@plt>
jmp    1132 <sys_sendmsg+0x12>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_sendmsg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <sendmsg@plt>
cmp    $0xffffffff,%eax
jne    1179 <sys_sendmsg+0x59>
mov    0x2e9f(%rip),%r15
mov    0x2e88(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1174 <sys_sendmsg+0x54>
xor    %eax,%eax
call   1040 <task_yield@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <sendmsg@plt>
cmp    $0xffffffff,%eax
je     1150 <sys_sendmsg+0x30>
jmp    1179 <sys_sendmsg+0x59>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.msghdr = type { i32 }
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @sys_sendmsg(i32 %0, %struct.msghdr* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.msghdr*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store %struct.msghdr* %1, %struct.msghdr** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %19, %3
%9 = load i32, i32* %4
%10 = load %struct.msghdr*, %struct.msghdr** %5
%11 = load i32, i32* %6
%12 = call i32 @sendmsg(i32 %9, %struct.msghdr* %10, i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %8
%16 = load i64, i64* @errno
%17 = load i64, i64* @EAGAIN
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (...) @task_yield()
br label %8
21: ; preds = %15, %8
%22 = load i32, i32* %7
ret i32 %22
}

LLVM IR (-O2):
%struct.msghdr = type { i32 }
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @sys_sendmsg(i32 %0, %struct.msghdr* %1, i32 %2) {
%4 = tail call i32 @sendmsg(i32 %0, %struct.msghdr* %1, i32 %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %14
6: ; preds = %3, %10
%7 = load i64, i64* @errno
%8 = load i64, i64* @EAGAIN
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = tail call i32 (...) @task_yield()
%12 = tail call i32 @sendmsg(i32 %0, %struct.msghdr* %1, i32 %2)
%13 = icmp eq i32 %12, -1
br i1 %13, label %6, label %14
14: ; preds = %10, %6, %3
%15 = phi i32 [ %4, %3 ], [ -1, %6 ], [ %12, %10 ]
ret i32 %15
}