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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
void example_setsockopt(int sock) {
  int yes = 1;
  if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) != 0) {
    perror("server: setsockopt() failed: ");
    close(sock);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<example_setsockopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     11a2 <example_setsockopt+0x62>
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<example_setsockopt>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jne    117c <example_setsockopt+0x3c>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe7d(%rip),%rdi
call   1050 <perror@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [30 x i8] c"server: setsockopt() failed: \00"
@EXIT_FAILURE = global i32 0
define void @example_setsockopt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
%4 = load i32, i32* %2
%5 = load i32, i32* @SOL_SOCKET
%6 = load i32, i32* @SO_REUSEADDR
%7 = call i64 @setsockopt(i32 %4, i32 %5, i32 %6, i32* %3, i32 4)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = call i32 @close(i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
ret void
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [30 x i8] c"server: setsockopt() failed: \00"
@EXIT_FAILURE = global i32 0
define void @example_setsockopt(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%4 = load i32, i32* @SOL_SOCKET
%5 = load i32, i32* @SO_REUSEADDR
%6 = call i64 @setsockopt(i32 %0, i32 %4, i32 %5, i32* %2, i32 4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @close(i32 %0)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
ret void
}