#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__ EINTR;
int _fix_errno();
scalar_t__ errno;
int listen(int, int);
int socket_listen(int fd, int backlog) {
  int ret;
  do {
    errno = 0;
    do {
      ret = ((listen(fd, backlog)));
    } while (ret < 0 && errno == EINTR);
  } while (0);
  ;
  if (ret < 0)
    return _fix_errno();
  return ret;
  ;
}


x86 assembly (clang, -O0):
<socket_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2eab(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <listen@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jge    1173 <socket_listen+0x53>
mov    0x2e80(%rip),%rax
mov    (%rax),%rax
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    113c <socket_listen+0x1c>
jmp    1183 <socket_listen+0x63>
cmpl   $0x0,-0x10(%rbp)
jge    119c <socket_listen+0x7c>
mov    $0x0,%al
call   1030 <_fix_errno@plt>
mov    %eax,-0x4(%rbp)
jmp    11a2 <socket_listen+0x82>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_listen>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2eae(%rip),%r14
movq   $0x0,(%r14)
mov    0x2e98(%rip),%r15
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <listen@plt>
test   %eax,%eax
jns    1155 <socket_listen+0x35>
mov    (%r15),%rcx
cmp    %rcx,(%r14)
je     1140 <socket_listen+0x20>
test   %eax,%eax
js     1164 <socket_listen+0x44>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_fix_errno@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i32 @socket_listen(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
br label %7
7: ; preds = %2
store i64 0, i64* @errno
br label %8
8: ; preds = %19, %7
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = call i32 @listen(i32 %9, i32 %10)
store i32 %11, i32* %6
br label %12
12: ; preds = %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br label %19
19: ; preds = %15, %12
%20 = phi i1 [ false, %12 ], [ %18, %15 ]
br i1 %20, label %8, label %21
21: ; preds = %19
br label %22
22: ; preds = %21
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (...) @_fix_errno()
store i32 %26, i32* %3
br label %29
27: ; preds = %22
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %27, %25
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i32 @socket_listen(i32 %0, i32 %1) {
store i64 0, i64* @errno
br label %3
3: ; preds = %3, %2
%4 = tail call i32 @listen(i32 %0, i32 %1)
%5 = icmp slt i32 %4, 0
%6 = load i64, i64* @errno
%7 = load i64, i64* @EINTR
%8 = icmp eq i64 %6, %7
%9 = select i1 %5, i1 %8, i1 false
br i1 %9, label %3, label %10
10: ; preds = %3
br i1 %5, label %11, label %13
11: ; preds = %10
%12 = tail call i32 (...) @_fix_errno()
br label %13
13: ; preds = %10, %11
%14 = phi i32 [ %12, %11 ], [ %4, %10 ]
ret i32 %14
}