#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 {
  int ifr_mtu;
  int /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SIOCSIFMTU;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fatal(char *);
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
void set_mtu(const char *dev, int mtu) {
  struct ifreq ifq;
  int fd;
  fd = socket(PF_INET, SOCK_DGRAM, 0);
  if (fd == -1)
    fatal("Could not get socket to set MTU");
  strcpy(ifq.ifr_name, dev);
  ifq.ifr_mtu = mtu;
  if (ioctl(fd, SIOCSIFMTU, &ifq) == -1)
    fatal("SIOCSIFMTU failed");
  close(fd);
}


x86 assembly (clang, -O0):
<set_mtu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1191 <set_mtu+0x41>
lea    0xe74(%rip),%rdi
call   1060 <fatal@plt>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11cd <set_mtu+0x7d>
lea    0xe58(%rip),%rdi
call   1060 <fatal@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_mtu>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    118a <set_mtu+0x3a>
lea    0xe7b(%rip),%rdi
call   1060 <fatal@plt>
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %r14d,0x8(%rsp)
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11bd <set_mtu+0x6d>
lea    0xe68(%rip),%rdi
call   1060 <fatal@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [32 x i8] c"Could not get socket to set MTU\00"
@SIOCSIFMTU = global i32 0
@.str.1 = [18 x i8] c"SIOCSIFMTU failed\00"
define void @set_mtu(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.ifreq
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 1
%16 = load i32, i32* %15
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i32 %16, i8* %17)
%19 = load i32, i32* %4
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %6
%22 = load i32, i32* @SIOCSIFMTU
%23 = call i32 @ioctl(i32 %21, i32 %22, %struct.ifreq* %5)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = call i32 @fatal(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %14
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [32 x i8] c"Could not get socket to set MTU\00"
@SIOCSIFMTU = global i32 0
@.str.1 = [18 x i8] c"SIOCSIFMTU failed\00"
define void @set_mtu(i8* %0, i32 %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 %9, label %11
9: ; preds = %2
%10 = tail call i32 @fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = tail call i32 @strcpy(i32 undef, i8* %0)
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
store i32 %1, i32* %13
%14 = load i32, i32* @SIOCSIFMTU
%15 = call i32 @ioctl(i32 %7, i32 %14, %struct.ifreq* %3)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @fatal(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %11
%20 = call i32 @close(i32 %7)
ret void
}