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

/* Variables and functions */
scalar_t__ EINTR;
int accept(int, struct sockaddr *, void *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int do_accept(int acc_sock, int *sock) {
  int ret;
  static struct sockaddr_in from;
  int len;
  memset((char *)&from, 0, sizeof(from));
  len = sizeof(from);
  ret = accept(acc_sock, (struct sockaddr *)&from, (void *)&len);
  if (ret == (-1)) {
    if (errno == EINTR) {
      printf("accept interrupted\n");
    }
    fprintf(stderr, "errno=%d ", errno);
    perror("accept");
    return (0);
  }
  *sock = ret;
  return (1);
}


x86 assembly (clang, -O0):
<do_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0x2eea(%rip),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
movl   $0x4,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rdx
lea    0x2ec9(%rip),%rsi
call   1070 <accept@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f6 <do_accept+0xa6>
mov    0x2e38(%rip),%rax
mov    (%rax),%rax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
jne    11bf <do_accept+0x6f>
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%rdx
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe39(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1206 <do_accept+0xb6>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_accept>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x2eec(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
movl   $0x4,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <accept@plt>
cmp    $0xffffffff,%eax
je     11a0 <do_accept+0x50>
mov    %eax,(%r14)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e31(%rip),%rbx
mov    (%rbx),%rdx
mov    0x2e1f(%rip),%rax
cmp    (%rax),%rdx
jne    11c5 <do_accept+0x75>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdx
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe29(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
jmp    1197 <do_accept+0x47>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@do_accept.from = internal global %struct.sockaddr_in zeroinitializer
@errno = global i64 0
@EINTR = global i64 0
@.str = [20 x i8] c"accept interrupted\0A\00"
@stderr = global i32 0
@.str.1 = [10 x i8] c"errno=%d \00"
@.str.2 = [7 x i8] c"accept\00"
define i32 @do_accept(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%8 = call i32 @memset(i8* bitcast (%struct.sockaddr_in* @do_accept.from to i8*), i32 0, i32 4)
store i32 4, i32* %7
%9 = load i32, i32* %4
%10 = bitcast i32* %7 to i8*
%11 = call i32 @accept(i32 %9, %struct.sockaddr* bitcast (%struct.sockaddr_in* @do_accept.from to %struct.sockaddr*), i8* %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %25
14: ; preds = %2
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINTR
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = load i32, i32* @stderr
%22 = load i64, i64* @errno
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %22)
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %28
25: ; preds = %2
%26 = load i32, i32* %6
%27 = load i32*, i32** %5
store i32 %26, i32* %27
store i32 1, i32* %3
br label %28
28: ; preds = %25, %20
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@do_accept.from = internal global %struct.sockaddr_in zeroinitializer
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str.1 = [10 x i8] c"errno=%d \00"
@.str.2 = [7 x i8] c"accept\00"
@str = [19 x i8] c"accept interrupted\00"
define i32 @do_accept(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @memset(i8* bitcast (%struct.sockaddr_in* @do_accept.from to i8*), i32 0, i32 4)
store i32 4, i32* %3
%6 = call i32 @accept(i32 %0, %struct.sockaddr* bitcast (%struct.sockaddr_in* @do_accept.from to %struct.sockaddr*), i8* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %20
8: ; preds = %2
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%14 = load i64, i64* @errno
br label %15
15: ; preds = %12, %8
%16 = phi i64 [ %14, %12 ], [ %9, %8 ]
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %16)
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %21
20: ; preds = %2
store i32 %6, i32* %1
br label %21
21: ; preds = %20, %15
%22 = phi i32 [ 0, %15 ], [ 1, %20 ]
ret i32 %22
}