#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;
  char *ifr_name;
  scalar_t__ ifr_flags;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCSIFMTU;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int ioctl(int, int /*<<< orphan*/, struct ifreq *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void set_mtu(struct ifreq *ifr, int mtu) {
  int sock;
  int rc;
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0) {
    fprintf(stderr, "socket(): %s\n", strerror(errno));
    return;
  }
  ifr->ifr_flags = 0;
  ifr->ifr_mtu = mtu;
  rc = ioctl(sock, SIOCSIFMTU, ifr);
  if (rc) {
    fprintf(stderr, "Failed to set MTU on %s: %s\n", ifr->ifr_name,
            strerror(errno));
  }
  close(sock);
}


x86 assembly (clang, -O0):
<set_mtu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11b8 <set_mtu+0x68>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1235 <set_mtu+0xe5>
mov    -0x8(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%edi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     122d <set_mtu+0xdd>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xde8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_mtu>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11d9 <set_mtu+0x89>
mov    %eax,%ebp
movq   $0x0,0x10(%rbx)
mov    %r14d,(%rbx)
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
je     11ce <set_mtu+0x7e>
mov    0x2e2e(%rip),%rax
mov    (%rax),%r14d
mov    0x8(%rbx),%rbx
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe50(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <close@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%ebx
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe09(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32, i8*, i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"socket(): %s\0A\00"
@errno = global i32 0
@SIOCSIFMTU = global i32 0
@.str.1 = [29 x i8] c"Failed to set MTU on %s: %s\0A\00"
define void @set_mtu(%struct.ifreq* %0, i32 %1) {
%3 = alloca %struct.ifreq*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.ifreq* %0, %struct.ifreq** %3
store i32 %1, i32* %4
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %40
17: ; preds = %2
%18 = load %struct.ifreq*, %struct.ifreq** %3
%19 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %18, i32 0, i32 2
store i64 0, i64* %19
%20 = load i32, i32* %4
%21 = load %struct.ifreq*, %struct.ifreq** %3
%22 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %5
%24 = load i32, i32* @SIOCSIFMTU
%25 = load %struct.ifreq*, %struct.ifreq** %3
%26 = call i32 @ioctl(i32 %23, i32 %24, %struct.ifreq* %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %17
%30 = load i32, i32* @stderr
%31 = load %struct.ifreq*, %struct.ifreq** %3
%32 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %31, i32 0, i32 1
%33 = load i8*, i8** %32
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %35)
br label %37
37: ; preds = %29, %17
%38 = load i32, i32* %5
%39 = call i32 @close(i32 %38)
br label %40
40: ; preds = %37, %12
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i8*, i64 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"socket(): %s\0A\00"
@errno = global i32 0
@SIOCSIFMTU = global i32 0
@.str.1 = [29 x i8] c"Failed to set MTU on %s: %s\0A\00"
define void @set_mtu(%struct.ifreq* %0, i32 %1) {
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %27
12: ; preds = %2
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %0, i64 0, i32 2
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %0, i64 0, i32 0
store i32 %1, i32* %14
%15 = load i32, i32* @SIOCSIFMTU
%16 = tail call i32 @ioctl(i32 %5, i32 %15, %struct.ifreq* %0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %0, i64 0, i32 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %23)
br label %25
25: ; preds = %18, %12
%26 = tail call i32 @close(i32 %5)
br label %27
27: ; preds = %25, %7
ret void
}