#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;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVBUF;
int /*<<< orphan*/ SO_SNDBUF;
int /*<<< orphan*/ close(int);
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int val;
  int s;
  int cc;
  socklen_t l;
  l = sizeof(int);
  s = socket(AF_INET, SOCK_STREAM, 0);
  cc = getsockopt(s, SOL_SOCKET, SO_RCVBUF, &val, &l);
  if (cc < 0) {
    perror("getsockopt");
    close(s);
    return -1;
  }
  printf("SO_RCVBUF: %d\n", val);
  l = sizeof(int);
  cc = getsockopt(s, SOL_SOCKET, SO_SNDBUF, &val, &l);
  if (cc < 0) {
    perror("getsockopt");
    close(s);
    return -1;
  }
  printf("SO_SNDBUF %d\n", val);
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x20(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1050 <getsockopt@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11d8 <main+0x88>
lea    0xe41(%rip),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <main+0x10b>
mov    -0x14(%rbp),%esi
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
movl   $0x4,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1050 <getsockopt@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    123d <main+0xed>
lea    0xddc(%rip),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <main+0x10b>
mov    -0x14(%rbp),%esi
lea    0xdd3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
movl   $0x4,(%rsp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
mov    0x2e6c(%rip),%rbp
mov    0x0(%rbp),%esi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
mov    %ebx,%edi
call   1050 <getsockopt@plt>
test   %eax,%eax
js     11f3 <main+0xa3>
mov    0x4(%rsp),%esi
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
movl   $0x4,(%rsp)
mov    0x0(%rbp),%esi
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
mov    %ebx,%edi
call   1050 <getsockopt@plt>
test   %eax,%eax
js     11f3 <main+0xa3>
mov    0x4(%rsp),%esi
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
xor    %ebp,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe06(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ebp
jmp    11e3 <main+0x93>

LLVM IR (-O0):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@.str = [11 x i8] c"getsockopt\00"
@.str.1 = [15 x i8] c"SO_RCVBUF: %d\0A\00"
@SO_SNDBUF = global i32 0
@.str.2 = [14 x i8] c"SO_SNDBUF %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %9
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_RCVBUF
%16 = call i32 @getsockopt(i32 %13, i32 %14, i32 %15, i32* %6, i32* %9)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %7
%22 = call i32 @close(i32 %21)
store i32 -1, i32* %3
br label %41
23: ; preds = %2
%24 = load i32, i32* %6
%25 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i32 4, i32* %9
%26 = load i32, i32* %7
%27 = load i32, i32* @SOL_SOCKET
%28 = load i32, i32* @SO_SNDBUF
%29 = call i32 @getsockopt(i32 %26, i32 %27, i32 %28, i32* %6, i32* %9)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %23
%33 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* %7
%35 = call i32 @close(i32 %34)
store i32 -1, i32* %3
br label %41
36: ; preds = %23
%37 = load i32, i32* %6
%38 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %7
%40 = call i32 @close(i32 %39)
store i32 0, i32* %3
br label %41
41: ; preds = %36, %32, %19
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_RCVBUF = global i32 0
@.str = [11 x i8] c"getsockopt\00"
@.str.1 = [15 x i8] c"SO_RCVBUF: %d\0A\00"
@SO_SNDBUF = global i32 0
@.str.2 = [14 x i8] c"SO_SNDBUF %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = load i32, i32* @SOL_SOCKET
%11 = load i32, i32* @SO_RCVBUF
%12 = call i32 @getsockopt(i32 %9, i32 %10, i32 %11, i32* %3, i32* %4)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %28
16: ; preds = %2
%17 = load i32, i32* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %17)
store i32 4, i32* %4
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_SNDBUF
%21 = call i32 @getsockopt(i32 %9, i32 %19, i32 %20, i32* %3, i32* %4)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %28
25: ; preds = %16
%26 = load i32, i32* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %23, %14
%29 = phi i32 [ -1, %14 ], [ -1, %23 ], [ 0, %25 ]
%30 = call i32 @close(i32 %9)
ret i32 %29
}