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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ err_ret(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int getsockopt(int, int /*<<< orphan*/, int, int *, int *);
int /*<<< orphan*/ printf(char *, char const *, int, int);
void print_int_sockopt(int fd, char const *optstr, int option) {
  int val = 0;
  socklen_t len = sizeof(val);
  int ret = getsockopt(fd, SOL_SOCKET, option, &val, &len);
  if (ret < 0) {
    err_ret("getsockopt for %s failed, errno %d", optstr, errno);
    return;
  }
  printf("%s [%d]: %d\n", optstr, len, val);
}


x86 assembly (clang, -O0):
<print_int_sockopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
lea    -0x18(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1040 <getsockopt@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1197 <print_int_sockopt+0x67>
mov    -0x10(%rbp),%rsi
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
lea    0xe73(%rip),%rdi
call   1050 <err_ret@plt>
jmp    11ad <print_int_sockopt+0x7d>
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_int_sockopt>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x4,0x8(%rsp)
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1040 <getsockopt@plt>
test   %eax,%eax
js     117d <print_int_sockopt+0x4d>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xeb0(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
jmp    1195 <print_int_sockopt+0x65>
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
lea    0xe73(%rip),%rdi
mov    %rbx,%rsi
call   1050 <err_ret@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@.str = [35 x i8] c"getsockopt for %s failed, errno %d\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"%s [%d]: %d\0A\00"
define void @print_int_sockopt(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* %7
store i32 4, i32* %8
%10 = load i32, i32* %4
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* %6
%13 = call i32 @getsockopt(i32 %10, i32 %11, i32 %12, i32* %7, i32* %8)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = load i32, i32* @errno
%19 = call i32 @err_ret(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %18)
br label %25
20: ; preds = %3
%21 = load i8*, i8** %5
%22 = load i32, i32* %8
%23 = load i32, i32* %7
%24 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %22, i32 %23)
br label %25
25: ; preds = %20, %16
ret void
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@.str = [35 x i8] c"getsockopt for %s failed, errno %d\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"%s [%d]: %d\0A\00"
define void @print_int_sockopt(i32 %0, i8* %1, i32 %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 = call i32 @getsockopt(i32 %0, i32 %8, i32 %2, i32* %4, i32* %5)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* @errno
%13 = call i32 @err_ret(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %12)
br label %18
14: ; preds = %3
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %15, i32 %16)
br label %18
18: ; preds = %14, %11
ret void
}