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

/* Variables and functions */
int /*<<< orphan*/ IPV6_MTU;
int /*<<< orphan*/ IP_MTU;
int /*<<< orphan*/ SOL_IP;
int /*<<< orphan*/ SOL_IPV6;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, unsigned int *,
               int *);
int /*<<< orphan*/ stderr;
unsigned int get_path_mtu(int fd, bool is_ipv4) {
  socklen_t vallen;
  unsigned int mtu;
  int ret;
  vallen = sizeof(mtu);
  if (is_ipv4)
    ret = getsockopt(fd, SOL_IP, IP_MTU, &mtu, &vallen);
  else
    ret = getsockopt(fd, SOL_IPV6, IPV6_MTU, &mtu, &vallen);
  if (ret)
    error(1, errno, "getsockopt mtu");
  fprintf(stderr, "path mtu (read):  %u\n", mtu);
  return mtu;
}


x86 assembly (clang, -O0):
<get_path_mtu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1179 <get_path_mtu+0x49>
mov    -0x4(%rbp),%edi
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
lea    -0xc(%rbp),%r8
call   1030 <getsockopt@plt>
mov    %eax,-0x14(%rbp)
jmp    119e <get_path_mtu+0x6e>
mov    -0x4(%rbp),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    0x2e3c(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
lea    -0xc(%rbp),%r8
call   1030 <getsockopt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c2 <get_path_mtu+0x92>
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe43(%rip),%rdx
call   1050 <error@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xe3a(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_path_mtu>:
push   %rax
test   %esi,%esi
mov    0x2ebe(%rip),%rax
cmove  0x2ea6(%rip),%rax
movl   $0x4,0x4(%rsp)
mov    (%rax),%esi
mov    0x2e6d(%rip),%rax
cmove  0x2e6d(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
lea    0x4(%rsp),%r8
call   1030 <getsockopt@plt>
test   %eax,%eax
je     1188 <get_path_mtu+0x58>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    0xe82(%rip),%rdx
mov    $0x1,%edi
call   1050 <error@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%edx
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
@SOL_IP = global i32 0
@IP_MTU = global i32 0
@SOL_IPV6 = global i32 0
@IPV6_MTU = global i32 0
@errno = global i32 0
@.str = [15 x i8] c"getsockopt mtu\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"path mtu (read): %u\0A\00"
define i32 @get_path_mtu(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
store i32 4, i32* %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* %3
%12 = load i32, i32* @SOL_IP
%13 = load i32, i32* @IP_MTU
%14 = call i32 @getsockopt(i32 %11, i32 %12, i32 %13, i32* %6, i32* %5)
store i32 %14, i32* %7
br label %20
15: ; preds = %2
%16 = load i32, i32* %3
%17 = load i32, i32* @SOL_IPV6
%18 = load i32, i32* @IPV6_MTU
%19 = call i32 @getsockopt(i32 %16, i32 %17, i32 %18, i32* %6, i32* %5)
store i32 %19, i32* %7
br label %20
20: ; preds = %15, %10
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @errno
%25 = call i32 @error(i32 1, i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %23, %20
%27 = load i32, i32* @stderr
%28 = load i32, i32* %6
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %6
ret i32 %30
}

LLVM IR (-O2):
@SOL_IP = global i32 0
@IP_MTU = global i32 0
@SOL_IPV6 = global i32 0
@IPV6_MTU = global i32 0
@errno = global i32 0
@.str = [15 x i8] c"getsockopt mtu\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"path mtu (read): %u\0A\00"
define i32 @get_path_mtu(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* %3
%7 = icmp eq i32 %1, 0
%8 = load i32, i32* @SOL_IPV6
%9 = load i32, i32* @SOL_IP
%10 = select i1 %7, i32 %8, i32 %9
%11 = load i32, i32* @IPV6_MTU
%12 = load i32, i32* @IP_MTU
%13 = select i1 %7, i32 %11, i32 %12
%14 = call i32 @getsockopt(i32 %0, i32 %10, i32 %13, i32* %4, i32* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = load i32, i32* @errno
%18 = call i32 @error(i32 1, i32 %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %16, %2
%20 = load i32, i32* @stderr
%21 = load i32, i32* %4
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %4
ret i32 %23
}