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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_SNDBUF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              char *, int *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int set_socket_opt(int s) {
  socklen_t optval, optsize;
  int b0 = 0;
  optval = 10 * 1024;
  b0 = setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&optval, sizeof(optval));
  if (b0 != 0)
    fprintf(stderr, "Error setting SEND BUFFER: SO_SNDBUF size \n");
  optval = 0;
  optsize = 4;
  getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *)&optval, &optsize);
  optval = 10 * 1024;
  b0 = setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&optval, sizeof(optval));
  if (b0 != 0)
    fprintf(stderr, "Error setting RECEIVE BUFFER: SO_RCVBUF size \n");
  optval = 0;
  optsize = 4;
  getsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&optval, &optsize);
  return (0);
}


x86 assembly (clang, -O0):
<set_socket_opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x2800,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     118f <set_socket_opt+0x5f>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%r8
call   1040 <getsockopt@plt>
movl   $0x2800,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
mov    0x2df7(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     120c <set_socket_opt+0xdc>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%r8
call   1040 <getsockopt@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_socket_opt>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
movl   $0x2800,(%rsp)
mov    0x2ea0(%rip),%r15
mov    (%r15),%esi
mov    0x2e8e(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
je     117c <set_socket_opt+0x4c>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,(%rsp)
movl   $0x4,0x4(%rsp)
mov    (%r15),%esi
mov    (%r14),%edx
mov    %rsp,%r14
lea    0x4(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rcx
call   1040 <getsockopt@plt>
movl   $0x2800,(%rsp)
mov    (%r15),%esi
mov    0x2e1c(%rip),%r12
mov    (%r12),%edx
mov    %ebx,%edi
mov    %r14,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
je     11e1 <set_socket_opt+0xb1>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,(%rsp)
movl   $0x4,0x4(%rsp)
mov    (%r15),%esi
mov    (%r12),%edx
mov    %rsp,%rcx
lea    0x4(%rsp),%r8
mov    %ebx,%edi
call   1040 <getsockopt@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Error setting SEND BUFFER: SO_SNDBUF size \0A\00"
@SO_RCVBUF = global i32 0
@.str.1 = [47 x i8] c"Error setting RECEIVE BUFFER: SO_RCVBUF size \0A\00"
define i32 @set_socket_opt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
store i32 10240, i32* %3
%6 = load i32, i32* %2
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_SNDBUF
%9 = bitcast i32* %3 to i8*
%10 = call i32 @setsockopt(i32 %6, i32 %7, i32 %8, i8* %9, i32 4)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %1
store i32 0, i32* %3
store i32 4, i32* %4
%17 = load i32, i32* %2
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_SNDBUF
%20 = bitcast i32* %3 to i8*
%21 = call i32 @getsockopt(i32 %17, i32 %18, i32 %19, i8* %20, i32* %4)
store i32 10240, i32* %3
%22 = load i32, i32* %2
%23 = load i32, i32* @SOL_SOCKET
%24 = load i32, i32* @SO_RCVBUF
%25 = bitcast i32* %3 to i8*
%26 = call i32 @setsockopt(i32 %22, i32 %23, i32 %24, i8* %25, i32 4)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %16
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %29, %16
store i32 0, i32* %3
store i32 4, i32* %4
%33 = load i32, i32* %2
%34 = load i32, i32* @SOL_SOCKET
%35 = load i32, i32* @SO_RCVBUF
%36 = bitcast i32* %3 to i8*
%37 = call i32 @getsockopt(i32 %33, i32 %34, i32 %35, i8* %36, i32* %4)
ret i32 0
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Error setting SEND BUFFER: SO_SNDBUF size \0A\00"
@SO_RCVBUF = global i32 0
@.str.1 = [47 x i8] c"Error setting RECEIVE BUFFER: SO_RCVBUF size \0A\00"
define i32 @set_socket_opt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 10240, i32* %2
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_SNDBUF
%8 = call i32 @setsockopt(i32 %0, i32 %6, i32 %7, i8* %4, i32 4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
store i32 0, i32* %2
store i32 4, i32* %3
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_SNDBUF
%16 = call i32 @getsockopt(i32 %0, i32 %14, i32 %15, i8* %4, i32* %3)
store i32 10240, i32* %2
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_RCVBUF
%19 = call i32 @setsockopt(i32 %0, i32 %17, i32 %18, i8* %4, i32 4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %13
store i32 0, i32* %2
store i32 4, i32* %3
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_RCVBUF
%27 = call i32 @getsockopt(i32 %0, i32 %25, i32 %26, i8* %4, i32* %3)
ret i32 0
}