#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;

/* Variables and functions */
int IPV6_MTU_DISCOVER;
int IPV6_PMTUDISC_DO;
int IP_MTU_DISCOVER;
int IP_PMTUDISC_DO;
int SOL_IP;
int SOL_IPV6;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
scalar_t__ setsockopt(int, int, int, int *, int);
void set_pmtu_discover(int fd, bool is_ipv4) {
  int level, name, val;
  if (is_ipv4) {
    level = SOL_IP;
    name = IP_MTU_DISCOVER;
    val = IP_PMTUDISC_DO;
  } else {
    level = SOL_IPV6;
    name = IPV6_MTU_DISCOVER;
    val = IPV6_PMTUDISC_DO;
  }
  if (setsockopt(fd, level, name, &val, sizeof(val)))
    error(1, errno, "setsockopt path mtu");
}


x86 assembly (clang, -O0):
<set_pmtu_discover>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1161 <set_pmtu_discover+0x41>
mov    0x2eb9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    1185 <set_pmtu_discover+0x65>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    -0x14(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     11c1 <set_pmtu_discover+0xa1>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe44(%rip),%rdx
call   1040 <error@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_pmtu_discover>:
push   %rax
test   %esi,%esi
mov    0x2ebe(%rip),%rdx
cmove  0x2e86(%rip),%rdx
mov    0x2ebf(%rip),%rcx
cmove  0x2e9f(%rip),%rcx
mov    0x2e80(%rip),%rax
cmove  0x2e70(%rip),%rax
mov    (%rdx),%edx
mov    (%rcx),%esi
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
je     1189 <set_pmtu_discover+0x69>
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdx
mov    $0x1,%edi
call   1040 <error@plt>
pop    %rax
ret

LLVM IR (-O0):
@SOL_IP = global i32 0
@IP_MTU_DISCOVER = global i32 0
@IP_PMTUDISC_DO = global i32 0
@SOL_IPV6 = global i32 0
@IPV6_MTU_DISCOVER = global i32 0
@IPV6_PMTUDISC_DO = global i32 0
@errno = global i32 0
@.str = [20 x i8] c"setsockopt path mtu\00"
define void @set_pmtu_discover(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @SOL_IP
store i32 %11, i32* %5
%12 = load i32, i32* @IP_MTU_DISCOVER
store i32 %12, i32* %6
%13 = load i32, i32* @IP_PMTUDISC_DO
store i32 %13, i32* %7
br label %18
14: ; preds = %2
%15 = load i32, i32* @SOL_IPV6
store i32 %15, i32* %5
%16 = load i32, i32* @IPV6_MTU_DISCOVER
store i32 %16, i32* %6
%17 = load i32, i32* @IPV6_PMTUDISC_DO
store i32 %17, i32* %7
br label %18
18: ; preds = %14, %10
%19 = load i32, i32* %3
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call i64 @setsockopt(i32 %19, i32 %20, i32 %21, i32* %7, i32 4)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* @errno
%26 = call i32 @error(i32 1, i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %24, %18
ret void
}

LLVM IR (-O2):
@SOL_IP = global i32 0
@IP_MTU_DISCOVER = global i32 0
@IP_PMTUDISC_DO = global i32 0
@SOL_IPV6 = global i32 0
@IPV6_MTU_DISCOVER = global i32 0
@IPV6_PMTUDISC_DO = global i32 0
@errno = global i32 0
@.str = [20 x i8] c"setsockopt path mtu\00"
define void @set_pmtu_discover(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %1, 0
%6 = load i32, i32* @IPV6_MTU_DISCOVER
%7 = load i32, i32* @IP_MTU_DISCOVER
%8 = select i1 %5, i32 %6, i32 %7
%9 = load i32, i32* @SOL_IPV6
%10 = load i32, i32* @SOL_IP
%11 = select i1 %5, i32 %9, i32 %10
%12 = load i32, i32* @IPV6_PMTUDISC_DO
%13 = load i32, i32* @IP_PMTUDISC_DO
%14 = select i1 %5, i32 %12, i32 %13
store i32 %14, i32* %3
%15 = call i64 @setsockopt(i32 %0, i32 %11, i32 %8, i32* %3, i32 4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i32, i32* @errno
%19 = call i32 @error(i32 1, i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %17, %2
ret void
}