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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ getsockopt(int, int /*<<< orphan*/, int, void *,
                      int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int getbuffsize(int sfd, int buffname) {
  int s;
  socklen_t slt = (socklen_t)sizeof(s);
  if (getsockopt(sfd, SOL_SOCKET, buffname, (void *)&s, &slt) < 0) {
    perror("getsockopt");
    exit(EXIT_FAILURE);
  }
  return s;
}


x86 assembly (clang, -O0):
<getbuffsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x4,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1030 <getsockopt@plt>
cmp    $0x0,%rax
jge    1185 <getbuffsize+0x55>
lea    0xe8e(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbuffsize>:
push   %rax
mov    %esi,%edx
movl   $0x4,(%rsp)
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
call   1030 <getsockopt@plt>
test   %rax,%rax
js     115b <getbuffsize+0x2b>
mov    0x4(%rsp),%eax
pop    %rcx
ret
lea    0xe9e(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@.str = [11 x i8] c"getsockopt\00"
@EXIT_FAILURE = global i32 0
define i32 @getbuffsize(i32 %0, i32 %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* @SOL_SOCKET
%8 = call i64 @getsockopt(i32 %0, i32 %7, i32 %1, i8* %5, i32* %4)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* %3
ret i32 %15
}