#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 */
typedef int /*<<< orphan*/ ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ i;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_SNDBUF;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *,
                      int *);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ warn(char *);
int /*<<< orphan*/ warnx(char *, int, ...);
void server(int s_listen) {
  char buffer[32768];
  ssize_t ssize_recv, ssize_send;
  socklen_t socklen;
  int i, s_accept;
  while (1) {
    s_accept = accept(s_listen, NULL, 0);
    if (s_accept >= 0) {
      i = (131072 - 16);
      if (setsockopt(s_accept, SOL_SOCKET, SO_RCVBUF, &i, sizeof(i)) < 0) {
        warn("server: setsockopt SO_RCVBUF");
        close(s_accept);
        continue;
      }
      if (getsockopt(s_accept, SOL_SOCKET, SO_RCVBUF, &i, &socklen) < 0) {
        warn("server: getsockopt SO_RCVBUF");
        close(s_accept);
        continue;
      }
      if (i != (131072 - 16)) {
        warnx("server: getsockopt SO_RCVBUF wrong %d", i);
        close(s_accept);
        continue;
      }
      socklen = sizeof(i);
      if (getsockopt(s_accept, SOL_SOCKET, SO_SNDBUF, &i, &socklen) < 0) {
        warn("server: getsockopt SO_SNDBUF");
        close(s_accept);
        continue;
      }
      if (i != (131072 - 16)) {
        warnx("server: getsockopt SO_SNDBUF wrong %d", i);
        close(s_accept);
        continue;
      }
      do {
        ssize_recv = recv(s_accept, buffer, sizeof(buffer), 0);
        if (ssize_recv == 0)
          break;
        if (ssize_recv < 0) {
          warn("server: recv");
          break;
        }
        ssize_send = send(s_accept, buffer, ssize_recv, 0);
        if (ssize_send == 0)
          break;
        if (ssize_send < 0) {
          warn("server: send");
          break;
        }
        if (ssize_send != ssize_recv)
          warnx("server: recv %zd sent %zd", ssize_recv, ssize_send);
      } while (1);
      close(s_accept);
    } else
      warn("server: accept");
  }
}


x86 assembly (clang, -O0):
<server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8030,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10a0 <accept@plt>
mov    %eax,-0x8024(%rbp)
cmpl   $0x0,-0x8024(%rbp)
jl     1411 <server+0x291>
movl   $0x1fff0,-0x8020(%rbp)
mov    -0x8024(%rbp),%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
lea    -0x8020(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0x0,%rax
jge    1209 <server+0x89>
lea    0xe0c(%rip),%rdi
call   1040 <warn@plt>
mov    -0x8024(%rbp),%edi
call   1080 <close@plt>
jmp    118e <server+0xe>
mov    -0x8024(%rbp),%edi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
lea    -0x8020(%rbp),%rcx
lea    -0x801c(%rbp),%r8
call   1090 <getsockopt@plt>
cmp    $0x0,%rax
jge    125a <server+0xda>
lea    0xdd8(%rip),%rdi
call   1040 <warn@plt>
mov    -0x8024(%rbp),%edi
call   1080 <close@plt>
jmp    118e <server+0xe>
cmpl   $0x1fff0,-0x8020(%rbp)
je     128e <server+0x10e>
mov    -0x8020(%rbp),%esi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
mov    -0x8024(%rbp),%edi
call   1080 <close@plt>
jmp    118e <server+0xe>
movl   $0x4,-0x801c(%rbp)
mov    -0x8024(%rbp),%edi
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
mov    0x2d32(%rip),%rax
mov    (%rax),%edx
lea    -0x8020(%rbp),%rcx
lea    -0x801c(%rbp),%r8
call   1090 <getsockopt@plt>
cmp    $0x0,%rax
jge    12e9 <server+0x169>
lea    0xd8c(%rip),%rdi
call   1040 <warn@plt>
mov    -0x8024(%rbp),%edi
call   1080 <close@plt>
jmp    118e <server+0xe>
cmpl   $0x1fff0,-0x8020(%rbp)
je     131d <server+0x19d>
mov    -0x8020(%rbp),%esi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
mov    -0x8024(%rbp),%edi
call   1080 <close@plt>
jmp    118e <server+0xe>
jmp    1322 <server+0x1a2>
mov    -0x8024(%rbp),%edi
lea    -0x8010(%rbp),%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x8014(%rbp)
cmpl   $0x0,-0x8014(%rbp)
jne    1353 <server+0x1d3>
jmp    1401 <server+0x281>
cmpl   $0x0,-0x8014(%rbp)
jge    1371 <server+0x1f1>
lea    0xd3c(%rip),%rdi
call   1040 <warn@plt>
jmp    1401 <server+0x281>
mov    -0x8024(%rbp),%edi
lea    -0x8010(%rbp),%rsi
mov    -0x8014(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x8018(%rbp)
cmpl   $0x0,-0x8018(%rbp)
jne    13a3 <server+0x223>
jmp    1401 <server+0x281>
cmpl   $0x0,-0x8018(%rbp)
jge    13c1 <server+0x241>
lea    0xcf9(%rip),%rdi
call   1040 <warn@plt>
jmp    1401 <server+0x281>
mov    -0x8018(%rbp),%eax
cmp    -0x8014(%rbp),%eax
je     13ed <server+0x26d>
mov    -0x8014(%rbp),%esi
mov    -0x8018(%rbp),%edx
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
jmp    13f2 <server+0x272>
mov    $0x1,%al
test   $0x1,%al
jne    1322 <server+0x1a2>
jmp    1401 <server+0x281>
mov    -0x8024(%rbp),%edi
call   1080 <close@plt>
jmp    141d <server+0x29d>
lea    0xcbf(%rip),%rdi
call   1040 <warn@plt>
jmp    118e <server+0xe>

x86 assembly (clang, -O2):
<server>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8018,%rsp
mov    %edi,%ebx
mov    0x2e4e(%rip),%rbp
mov    0x2e2f(%rip),%r12
lea    0x8(%rsp),%r14
jmp    11bc <server+0x3c>
lea    0xef4(%rip),%rdi
call   1040 <warn@plt>
mov    %r15d,%edi
call   1080 <close@plt>
lea    0xe3d(%rip),%r13
jmp    11dc <server+0x5c>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xf00(%rip),%rdi
call   1040 <warn@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <accept@plt>
test   %eax,%eax
js     11d0 <server+0x50>
mov    %eax,%r15d
movl   $0x1fff0,0x8(%rsp)
mov    0x0(%rbp),%esi
mov    (%r12),%edx
mov    %eax,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
test   %rax,%rax
js     1280 <server+0x100>
mov    0x0(%rbp),%esi
mov    (%r12),%edx
mov    %r15d,%edi
mov    %r14,%rcx
lea    0xc(%rsp),%r8
call   1090 <getsockopt@plt>
test   %rax,%rax
js     1285 <server+0x105>
mov    0x8(%rsp),%esi
cmp    $0x1fff0,%esi
jne    128e <server+0x10e>
movl   $0x4,0xc(%rsp)
mov    0x0(%rbp),%esi
mov    0x2d94(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %r14,%rcx
lea    0xc(%rsp),%r8
call   1090 <getsockopt@plt>
test   %rax,%rax
js     129e <server+0x11e>
mov    0x8(%rsp),%esi
cmp    $0x1fff0,%esi
je     12e8 <server+0x168>
lea    0xe07(%rip),%rdi
jmp    1295 <server+0x115>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
jmp    12b0 <server+0x130>
lea    0xd91(%rip),%rdi
jmp    12b0 <server+0x130>
lea    0xda5(%rip),%rdi
xor    %eax,%eax
call   1070 <warnx@plt>
jmp    12b5 <server+0x135>
lea    0xdbb(%rip),%rdi
cs nopw 0x0(%rax,%rax,1)
nop
call   1040 <warn@plt>
mov    %r15d,%edi
call   1080 <close@plt>
jmp    11dc <server+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %r13d,%eax
je     12e8 <server+0x168>
lea    0xde1(%rip),%rdi
mov    %r13d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <warnx@plt>
mov    %r15d,%edi
lea    0x10(%rsp),%rsi
mov    $0x8000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r13d
test   %eax,%eax
je     11b4 <server+0x34>
test   %r13d,%r13d
js     11a8 <server+0x28>
mov    %r15d,%edi
lea    0x10(%rsp),%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
je     11b4 <server+0x34>
jns    12d0 <server+0x150>
lea    0xd7d(%rip),%rdi
jmp    11af <server+0x2f>

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@.str = [29 x i8] c"server: setsockopt SO_RCVBUF\00"
@.str.1 = [29 x i8] c"server: getsockopt SO_RCVBUF\00"
@.str.2 = [38 x i8] c"server: getsockopt SO_RCVBUF wrong %d\00"
@SO_SNDBUF = global i32 0
@.str.3 = [29 x i8] c"server: getsockopt SO_SNDBUF\00"
@.str.4 = [38 x i8] c"server: getsockopt SO_SNDBUF wrong %d\00"
@.str.5 = [13 x i8] c"server: recv\00"
@.str.6 = [13 x i8] c"server: send\00"
@.str.7 = [26 x i8] c"server: recv %zd sent %zd\00"
@.str.8 = [15 x i8] c"server: accept\00"
define void @server(i32 %0) {
%2 = alloca i32
%3 = alloca [32768 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
br label %9
9: ; preds = %1, %20, %30, %37, %48, %55, %101
%10 = load i32, i32* %2
%11 = call i32 @accept(i32 %10, i32* null, i32 0)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %99
14: ; preds = %9
store i32 131056, i32* %7
%15 = load i32, i32* %8
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_RCVBUF
%18 = call i64 @setsockopt(i32 %15, i32 %16, i32 %17, i32* %7, i32 4)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = call i32 @warn(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* %8
%23 = call i32 @close(i32 %22)
br label %9
24: ; preds = %14
%25 = load i32, i32* %8
%26 = load i32, i32* @SOL_SOCKET
%27 = load i32, i32* @SO_RCVBUF
%28 = call i64 @getsockopt(i32 %25, i32 %26, i32 %27, i32* %7, i32* %6)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = call i32 @warn(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* %8
%33 = call i32 @close(i32 %32)
br label %9
34: ; preds = %24
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 131056
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i32, i32* %7
%39 = call i32 (i8*, i32, ...) @warnx(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %8
%41 = call i32 @close(i32 %40)
br label %9
42: ; preds = %34
store i32 4, i32* %6
%43 = load i32, i32* %8
%44 = load i32, i32* @SOL_SOCKET
%45 = load i32, i32* @SO_SNDBUF
%46 = call i64 @getsockopt(i32 %43, i32 %44, i32 %45, i32* %7, i32* %6)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %42
%49 = call i32 @warn(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32, i32* %8
%51 = call i32 @close(i32 %50)
br label %9
52: ; preds = %42
%53 = load i32, i32* %7
%54 = icmp ne i32 %53, 131056
br i1 %54, label %55, label %60
55: ; preds = %52
%56 = load i32, i32* %7
%57 = call i32 (i8*, i32, ...) @warnx(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = load i32, i32* %8
%59 = call i32 @close(i32 %58)
br label %9
60: ; preds = %52
br label %61
61: ; preds = %95, %60
%62 = load i32, i32* %8
%63 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 0
%64 = call i32 @recv(i32 %62, i8* %63, i32 32768, i32 0)
store i32 %64, i32* %4
%65 = load i32, i32* %4
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %61
br label %96
68: ; preds = %61
%69 = load i32, i32* %4
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 @warn(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %96
73: ; preds = %68
%74 = load i32, i32* %8
%75 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 0
%76 = load i32, i32* %4
%77 = call i32 @send(i32 %74, i8* %75, i32 %76, i32 0)
store i32 %77, i32* %5
%78 = load i32, i32* %5
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %73
br label %96
81: ; preds = %73
%82 = load i32, i32* %5
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = call i32 @warn(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
br label %96
86: ; preds = %81
%87 = load i32, i32* %5
%88 = load i32, i32* %4
%89 = icmp ne i32 %87, %88
br i1 %89, label %90, label %94
90: ; preds = %86
%91 = load i32, i32* %4
%92 = load i32, i32* %5
%93 = call i32 (i8*, i32, ...) @warnx(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %91, i32 %92)
br label %94
94: ; preds = %90, %86
br label %95
95: ; preds = %94
br i1 true, label %61, label %96
96: ; preds = %95, %84, %80, %71, %67
%97 = load i32, i32* %8
%98 = call i32 @close(i32 %97)
br label %101
99: ; preds = %9
%100 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %101
101: ; preds = %99, %96
br label %9
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@.str = [29 x i8] c"server: setsockopt SO_RCVBUF\00"
@.str.1 = [29 x i8] c"server: getsockopt SO_RCVBUF\00"
@.str.2 = [38 x i8] c"server: getsockopt SO_RCVBUF wrong %d\00"
@SO_SNDBUF = global i32 0
@.str.3 = [29 x i8] c"server: getsockopt SO_SNDBUF\00"
@.str.4 = [38 x i8] c"server: getsockopt SO_SNDBUF wrong %d\00"
@.str.5 = [13 x i8] c"server: recv\00"
@.str.6 = [13 x i8] c"server: send\00"
@.str.7 = [26 x i8] c"server: recv %zd sent %zd\00"
@.str.8 = [15 x i8] c"server: accept\00"
define void @server(i32 %0) {
%2 = alloca [32768 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
br label %8
8: ; preds = %70, %1
%9 = call i32 @accept(i32 %0, i32* null, i32 0)
%10 = icmp sgt i32 %9, -1
br i1 %10, label %11, label %71
11: ; preds = %8
store i32 131056, i32* %4
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_RCVBUF
%14 = call i64 @setsockopt(i32 %9, i32 %12, i32 %13, i32* %4, i32 4)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = call i32 @warn(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @close(i32 %9)
br label %70
19: ; preds = %11
%20 = load i32, i32* @SOL_SOCKET
%21 = load i32, i32* @SO_RCVBUF
%22 = call i64 @getsockopt(i32 %9, i32 %20, i32 %21, i32* %4, i32* %3)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = call i32 @warn(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @close(i32 %9)
br label %70
27: ; preds = %19
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 131056
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = call i32 (i8*, i32, ...) @warnx(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%32 = call i32 @close(i32 %9)
br label %70
33: ; preds = %27
store i32 4, i32* %3
%34 = load i32, i32* @SOL_SOCKET
%35 = load i32, i32* @SO_SNDBUF
%36 = call i64 @getsockopt(i32 %9, i32 %34, i32 %35, i32* %4, i32* %3)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = call i32 @warn(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @close(i32 %9)
br label %70
41: ; preds = %33
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 131056
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = call i32 @recv(i32 %9, i8* %5, i32 32768, i32 0)
%46 = icmp eq i32 %45, 0
br i1 %46, label %68, label %50
47: ; preds = %41
%48 = call i32 (i8*, i32, ...) @warnx(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%49 = call i32 @close(i32 %9)
br label %70
50: ; preds = %44, %62
%51 = phi i32 [ %63, %62 ], [ %45, %44 ]
%52 = icmp slt i32 %51, 0
br i1 %52, label %65, label %53
53: ; preds = %50
%54 = call i32 @send(i32 %9, i8* %5, i32 %51, i32 0)
%55 = icmp eq i32 %54, 0
br i1 %55, label %68, label %56
56: ; preds = %53
%57 = icmp slt i32 %54, 0
br i1 %57, label %65, label %58
58: ; preds = %56
%59 = icmp eq i32 %54, %51
br i1 %59, label %62, label %60
60: ; preds = %58
%61 = call i32 (i8*, i32, ...) @warnx(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %51, i32 %54)
br label %62
62: ; preds = %58, %60
%63 = call i32 @recv(i32 %9, i8* %5, i32 32768, i32 0)
%64 = icmp eq i32 %63, 0
br i1 %64, label %68, label %50
65: ; preds = %56, %50
%66 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), %50 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), %56 ]
%67 = call i32 @warn(i8* %66)
br label %68
68: ; preds = %62, %53, %65, %44
%69 = call i32 @close(i32 %9)
br label %70
70: ; preds = %68, %71, %16, %24, %30, %38, %47
br label %8
71: ; preds = %8
%72 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %70
}