#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*/ SOL_SOCKET;
int getsockopt(int, int /*<<< orphan*/, int, int *, int *);
int /*<<< orphan*/ print_error(char *);
int _get_socket_option(int fd, int option_name) {
  int return_code;
  socklen_t option;
  socklen_t option_length = sizeof option;
  return_code =
      getsockopt(fd, SOL_SOCKET, option_name, &option, &option_length);
  if (return_code == -1) {
    print_error("Error getting socket option");
    return -1;
  }
  return option;
}


x86 assembly (clang, -O0):
<_get_socket_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x4,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1040 <getsockopt@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1176 <_get_socket_option+0x56>
lea    0xe9b(%rip),%rdi
call   1030 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    117c <_get_socket_option+0x5c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_socket_option>:
push   %rax
mov    %esi,%edx
movl   $0x4,(%rsp)
mov    0x2eb7(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rcx
mov    %rsp,%r8
call   1040 <getsockopt@plt>
cmp    $0xffffffff,%eax
je     114b <_get_socket_option+0x2b>
mov    0x4(%rsp),%eax
pop    %rcx
ret
lea    0xeae(%rip),%rdi
call   1030 <print_error@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@.str = [28 x i8] c"Error getting socket option\00"
define i32 @_get_socket_option(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 4, i32* %8
%9 = load i32, i32* %4
%10 = load i32, i32* @SOL_SOCKET
%11 = load i32, i32* %5
%12 = call i32 @getsockopt(i32 %9, i32 %10, i32 %11, i32* %7, i32* %8)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @print_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %19
17: ; preds = %2
%18 = load i32, i32* %7
store i32 %18, i32* %3
br label %19
19: ; preds = %17, %15
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@.str = [28 x i8] c"Error getting socket option\00"
define i32 @_get_socket_option(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 i32 @getsockopt(i32 %0, i32 %7, i32 %1, i32* %3, i32* %4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @print_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %14
12: ; preds = %2
%13 = load i32, i32* %3
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ -1, %10 ], [ %13, %12 ]
ret i32 %15
}