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

/* Variables and functions */
int /*<<< orphan*/ SIOCSIFMTU;
int /*<<< orphan*/ close(int);
int get_ctl_fd();
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int set_mtu(char *dev, int mtu) {
  struct ifreq ifr;
  int s;
  s = get_ctl_fd();
  if (s < 0)
    return -1;
  memset(&ifr, 0, sizeof(ifr));
  strcpy(ifr.ifr_name, dev);
  ifr.ifr_mtu = mtu;
  if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
    perror("SIOCSIFMTU");
    close(s);
    return -1;
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<set_mtu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1080 <get_ctl_fd@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    118f <set_mtu+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <set_mtu+0x9f>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    11f0 <set_mtu+0x90>
lea    0xe29(%rip),%rdi
call   1070 <perror@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <set_mtu+0x9f>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_mtu>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
xor    %r15d,%r15d
xor    %eax,%eax
call   1080 <get_ctl_fd@plt>
test   %eax,%eax
js     11c8 <set_mtu+0x68>
mov    %eax,%ebp
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14d,0x8(%rsp)
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r12,%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
js     11de <set_mtu+0x7e>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    11ce <set_mtu+0x6e>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1b(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%r15d
jmp    11bf <set_mtu+0x5f>

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

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@SIOCSIFMTU = global i32 0
@.str = [11 x i8] c"SIOCSIFMTU\00"
define i32 @set_mtu(i8* %0, i32 %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = tail call i32 (...) @get_ctl_fd()
%6 = icmp slt i32 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = call i32 @memset(%struct.ifreq* %3, i32 0, i32 8)
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 1
%10 = load i32, i32* %9
%11 = call i32 @strcpy(i32 %10, i8* %0)
%12 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
store i32 %1, i32* %12
%13 = load i32, i32* @SIOCSIFMTU
%14 = call i64 @ioctl(i32 %5, i32 %13, %struct.ifreq* %3)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %7
%17 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %7, %16
%19 = phi i32 [ -1, %16 ], [ 0, %7 ]
%20 = call i32 @close(i32 %5)
br label %21
21: ; preds = %18, %2
%22 = phi i32 [ -1, %2 ], [ %19, %18 ]
ret i32 %22
}