#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 */
scalar_t__ ECONNREFUSED;
int /*<<< orphan*/ MSG_DONTWAIT;
scalar_t__ errno;
int /*<<< orphan*/ error(int, scalar_t__, char *);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
void send_until_errconn(int fd) {
  int ret;
retry:
  ret = send(fd, "a", 1, MSG_DONTWAIT);
  if (ret == 1) {
    sleep(1);
    goto retry;
  }
  if (ret != -1)
    error(1, 0, "sendto: expected err");
  if (errno != ECONNREFUSED)
    error(1, errno, "sendto");
}


x86 assembly (clang, -O0):
<send_until_errconn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%ecx
lea    0xeb2(%rip),%rsi
mov    $0x1,%edx
call   1030 <send@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1174 <send_until_errconn+0x44>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    113b <send_until_errconn+0xb>
cmpl   $0xffffffff,-0x8(%rbp)
je     1193 <send_until_errconn+0x63>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xe74(%rip),%rdx
call   1040 <error@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%rax
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%rax
je     11c8 <send_until_errconn+0x98>
mov    0x2e24(%rip),%rax
mov    (%rax),%rsi
mov    $0x1,%edi
lea    0xe54(%rip),%rdx
call   1040 <error@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_until_errconn>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    0x2e92(%rip),%r15
lea    0xebb(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%ecx
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <send@plt>
cmp    $0x1,%eax
jne    1173 <send_until_errconn+0x43>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1150 <send_until_errconn+0x20>
cmp    $0xffffffff,%eax
je     118b <send_until_errconn+0x5b>
lea    0xe83(%rip),%rdx
mov    $0x1,%edi
xor    %esi,%esi
call   1040 <error@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%rsi
mov    0x2e4c(%rip),%rax
cmp    (%rax),%rsi
jne    11a7 <send_until_errconn+0x77>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe69(%rip),%rdx
mov    $0x1,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <error@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@MSG_DONTWAIT = global i32 0
@.str.1 = [21 x i8] c"sendto: expected err\00"
@errno = global i64 0
@ECONNREFUSED = global i64 0
@.str.2 = [7 x i8] c"sendto\00"
define void @send_until_errconn(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
br label %4
4: ; preds = %10, %1
%5 = load i32, i32* %2
%6 = load i32, i32* @MSG_DONTWAIT
%7 = call i32 @send(i32 %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = call i32 @sleep(i32 1)
br label %4
12: ; preds = %4
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @error(i32 1, i64 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = load i64, i64* @errno
%19 = load i64, i64* @ECONNREFUSED
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i64, i64* @errno
%23 = call i32 @error(i32 1, i64 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %21, %17
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@MSG_DONTWAIT = global i32 0
@.str.1 = [21 x i8] c"sendto: expected err\00"
@errno = global i64 0
@ECONNREFUSED = global i64 0
@.str.2 = [7 x i8] c"sendto\00"
define void @send_until_errconn(i32 %0) {
br label %2
2: ; preds = %5, %1
%3 = load i32, i32* @MSG_DONTWAIT
%4 = tail call i32 @send(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1, i32 %3)
switch i32 %4, label %7 [
i32 1, label %5
i32 -1, label %9
]
5: ; preds = %2
%6 = tail call i32 @sleep(i32 1)
br label %2
7: ; preds = %2
%8 = tail call i32 @error(i32 1, i64 0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %2, %7
%10 = load i64, i64* @errno
%11 = load i64, i64* @ECONNREFUSED
%12 = icmp eq i64 %10, %11
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @error(i32 1, i64 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
ret void
}