#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*/ a;

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_SNDBUF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ 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 socketfd;
  if ((socketfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
    perror("fail to socket");
    exit(-1);
  }
  int a;
  socklen_t b = sizeof(a);
  getsockopt(socketfd, SOL_SOCKET, SO_SNDBUF, &a, &b);
  printf("the bufsize is %d\n", a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    119a <main+0x4a>
lea    0xe75(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
movl   $0x4,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1040 <getsockopt@plt>
mov    -0xc(%rbp),%esi
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11aa <main+0x5a>
movl   $0x4,(%rsp)
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e5b(%rip),%rcx
mov    (%rcx),%edx
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
mov    %eax,%edi
call   1040 <getsockopt@plt>
mov    0x4(%rsp),%esi
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe4f(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"fail to socket\00"
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@.str.1 = [19 x i8] c"the bufsize is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
store i32 4, i32* %4
%13 = load i32, i32* %2
%14 = load i32, i32* @SOL_SOCKET
%15 = load i32, i32* @SO_SNDBUF
%16 = call i32 @getsockopt(i32 %13, i32 %14, i32 %15, i32* %3, i32* %4)
%17 = load i32, i32* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %17)
ret i32 0
}

LLVM IR (-O2):
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"fail to socket\00"
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
@.str.1 = [19 x i8] c"the bufsize is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = bitcast i32* %1 to i8*
%12 = bitcast i32* %2 to i8*
store i32 4, i32* %2
%13 = load i32, i32* @SOL_SOCKET
%14 = load i32, i32* @SO_SNDBUF
%15 = call i32 @getsockopt(i32 %5, i32 %13, i32 %14, i32* %1, i32* %2)
%16 = load i32, i32* %1
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %16)
ret i32 0
}