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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_SNDBUF;
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int *);
int get_sndbuf(int fd, void *optval, int *optlen) {
  int rc;
  int buf = 0;
  socklen_t koptlen = sizeof(buf);
  rc = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &buf, &koptlen);
  if (rc == 0)
    *(int *)optval = buf;
  return rc;
}


x86 assembly (clang, -O0):
<get_sndbuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
mov    0x2e9c(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1030 <getsockopt@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1169 <get_sndbuf+0x59>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sndbuf>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0x0,0x8(%rsp)
movl   $0x4,0xc(%rsp)
mov    0x2eb9(%rip),%rax
mov    (%rax),%esi
mov    0x2ea8(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1030 <getsockopt@plt>
test   %eax,%eax
jne    1153 <get_sndbuf+0x43>
mov    0x8(%rsp),%ecx
mov    %ecx,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
define i32 @get_sndbuf(i32 %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32* %2, i32** %6
store i32 0, i32* %8
store i32 4, i32* %9
%10 = load i32, i32* %4
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_SNDBUF
%13 = call i32 @getsockopt(i32 %10, i32 %11, i32 %12, i32* %8, i32* %9)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* %8
%18 = load i8*, i8** %5
%19 = bitcast i8* %18 to i32*
store i32 %17, i32* %19
br label %20
20: ; preds = %16, %3
%21 = load i32, i32* %7
ret i32 %21
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_SNDBUF = global i32 0
define i32 @get_sndbuf(i32 %0, i8* nocapture writeonly %1, i32* nocapture readnone %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = bitcast i32* %5 to i8*
store i32 4, i32* %5
%8 = load i32, i32* @SOL_SOCKET
%9 = load i32, i32* @SO_SNDBUF
%10 = call i32 @getsockopt(i32 %0, i32 %8, i32 %9, i32* %4, i32* %5)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i32, i32* %4
%14 = bitcast i8* %1 to i32*
store i32 %13, i32* %14
br label %15
15: ; preds = %12, %3
ret i32 %10
}