#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 sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ strerror(scalar_t__);
int /*<<< orphan*/ wheatSetError(char *, char *, int /*<<< orphan*/);
int wheatGenericAccept(char *err, int s, struct sockaddr *sa, socklen_t *len) {
  int fd;
  while (1) {
    fd = accept(s, sa, len);
    if (fd == -1) {
      if (errno == EINTR)
        continue;
      else if (errno == EAGAIN) {
        return -1;
      } else {
        wheatSetError(err, "accept: %s", strerror(errno));
        return -1;
      }
    }
    break;
  }
  return fd;
}


x86 assembly (clang, -O0):
<wheatGenericAccept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <accept@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11de <wheatGenericAccept+0xae>
mov    0x2e75(%rip),%rax
mov    (%rax),%rax
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%rax
jne    1183 <wheatGenericAccept+0x53>
jmp    1147 <wheatGenericAccept+0x17>
mov    0x2e56(%rip),%rax
mov    (%rax),%rax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
jne    11a9 <wheatGenericAccept+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <wheatGenericAccept+0xb9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xe33(%rip),%rsi
call   1040 <wheatSetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <wheatGenericAccept+0xb9>
jmp    11e3 <wheatGenericAccept+0xb3>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wheatGenericAccept>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %esi,%ebx
mov    %rdi,(%rsp)
mov    0x2e92(%rip),%r13
mov    0x2e83(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11a0 <wheatGenericAccept+0x70>
mov    0x0(%r13),%rdi
cmp    (%r14),%rdi
je     1160 <wheatGenericAccept+0x30>
mov    0x2e44(%rip),%rax
cmp    (%rax),%rdi
je     11a0 <wheatGenericAccept+0x70>
call   1050 <strerror@plt>
lea    0xe6b(%rip),%rsi
mov    (%rsp),%rdi
mov    %eax,%edx
call   1040 <wheatSetError@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@.str = [11 x i8] c"accept: %s\00"
define i32 @wheatGenericAccept(i8* %0, i32 %1, %struct.sockaddr* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr*
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store %struct.sockaddr* %2, %struct.sockaddr** %8
store i32* %3, i32** %9
br label %11
11: ; preds = %4, %22
%12 = load i32, i32* %7
%13 = load %struct.sockaddr*, %struct.sockaddr** %8
%14 = load i32*, i32** %9
%15 = call i32 @accept(i32 %12, %struct.sockaddr* %13, i32* %14)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %33
18: ; preds = %11
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINTR
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
br label %11
23: ; preds = %18
%24 = load i64, i64* @errno
%25 = load i64, i64* @EAGAIN
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -1, i32* %5
br label %36
28: ; preds = %23
%29 = load i8*, i8** %6
%30 = load i64, i64* @errno
%31 = call i32 @strerror(i64 %30)
%32 = call i32 @wheatSetError(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %31)
store i32 -1, i32* %5
br label %36
33: ; preds = %11
br label %34
34: ; preds = %33
%35 = load i32, i32* %10
store i32 %35, i32* %5
br label %36
36: ; preds = %34, %28, %27
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@.str = [11 x i8] c"accept: %s\00"
define i32 @wheatGenericAccept(i8* %0, i32 %1, %struct.sockaddr* %2, i32* %3) {
br label %5
5: ; preds = %8, %4
%6 = tail call i32 @accept(i32 %1, %struct.sockaddr* %2, i32* %3)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %5, label %12
12: ; preds = %8
%13 = load i64, i64* @EAGAIN
%14 = icmp eq i64 %9, %13
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = tail call i32 @strerror(i64 %9)
%17 = tail call i32 @wheatSetError(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %5, %12, %15
ret i32 %6
}