#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 */
struct ifreq {
  short ifr_mtu;
  int /*<<< orphan*/ ifr_name;
};
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIOCGIFMTU;
int /*<<< orphan*/ SIOCSIFMTU;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlcpy(int /*<<< orphan*/, char const *, int);
int if_domtu(const char *ifname, short int mtu) {
  int s, r;
  struct ifreq ifr;
  if ((s = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
    return -1;
  memset(&ifr, 0, sizeof(ifr));
  strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
  ifr.ifr_mtu = mtu;
  r = ioctl(s, mtu ? SIOCSIFMTU : SIOCGIFMTU, &ifr);
  close(s);
  if (r == -1)
    return -1;
  return ifr.ifr_mtu;
}


x86 assembly (clang, -O0):
<if_domtu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %rdi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1194 <if_domtu+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    1224 <if_domtu+0xd4>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1060 <strlcpy@plt>
mov    -0x12(%rbp),%ax
mov    %ax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movswl -0x12(%rbp),%eax
cmp    $0x0,%eax
je     11e1 <if_domtu+0x91>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    11ed <if_domtu+0x9d>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    121d <if_domtu+0xcd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1224 <if_domtu+0xd4>
movswl -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<if_domtu>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r15
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     11e6 <if_domtu+0x96>
mov    %eax,%ebp
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0xc(%rsp),%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1060 <strlcpy@plt>
mov    %bx,0x8(%rsp)
test   %bx,%bx
jne    11bf <if_domtu+0x6f>
mov    0x2e2b(%rip),%rax
jmp    11c6 <if_domtu+0x76>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r12,%rdx
call   1040 <ioctl@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%ebx
je     11e6 <if_domtu+0x96>
movswl 0x8(%rsp),%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i16, i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCSIFMTU = global i32 0
@SIOCGIFMTU = global i32 0
define i32 @if_domtu(i8* %0, i16 signext %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.ifreq
store i8* %0, i8** %4
store i16 %1, i16* %5
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %42
14: ; preds = %2
%15 = call i32 @memset(%struct.ifreq* %8, i32 0, i32 8)
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 1
%17 = load i32, i32* %16
%18 = load i8*, i8** %4
%19 = call i32 @strlcpy(i32 %17, i8* %18, i32 4)
%20 = load i16, i16* %5
%21 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
store i16 %20, i16* %21
%22 = load i32, i32* %6
%23 = load i16, i16* %5
%24 = sext i16 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %14
%27 = load i32, i32* @SIOCSIFMTU
br label %30
28: ; preds = %14
%29 = load i32, i32* @SIOCGIFMTU
br label %30
30: ; preds = %28, %26
%31 = phi i32 [ %27, %26 ], [ %29, %28 ]
%32 = call i32 @ioctl(i32 %22, i32 %31, %struct.ifreq* %8)
store i32 %32, i32* %7
%33 = load i32, i32* %6
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %30
store i32 -1, i32* %3
br label %42
38: ; preds = %30
%39 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%40 = load i16, i16* %39
%41 = sext i16 %40 to i32
store i32 %41, i32* %3
br label %42
42: ; preds = %38, %37, %13
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.ifreq = type { i16, i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SIOCSIFMTU = global i32 0
@SIOCGIFMTU = global i32 0
define i32 @if_domtu(i8* %0, i16 signext %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %25, label %9
9: ; preds = %2
%10 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 8)
%11 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%12 = load i32, i32* %11
%13 = call i32 @strlcpy(i32 %12, i8* %0, i32 4)
%14 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
store i16 %1, i16* %14
%15 = icmp eq i16 %1, 0
%16 = load i32, i32* @SIOCSIFMTU
%17 = load i32, i32* @SIOCGIFMTU
%18 = select i1 %15, i32 %17, i32 %16
%19 = call i32 @ioctl(i32 %7, i32 %18, %struct.ifreq* %3)
%20 = call i32 @close(i32 %7)
%21 = icmp eq i32 %19, -1
br i1 %21, label %25, label %22
22: ; preds = %9
%23 = load i16, i16* %14
%24 = sext i16 %23 to i32
br label %25
25: ; preds = %9, %2, %22
%26 = phi i32 [ %24, %22 ], [ -1, %2 ], [ -1, %9 ]
ret i32 %26
}