#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*/ IFNAMSIZ;
int /*<<< orphan*/ SIOCGIFMTU;
int interfaceIoctl(int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *,
                           int /*<<< orphan*/);
int tunGetMtu(const char *dev, int *mtu) {
  struct ifreq ifr;
  int err;
  memset(&ifr, 0, sizeof(ifr));
  ;
  strncpy(ifr.ifr_name, dev, IFNAMSIZ);
  if ((err = interfaceIoctl(SIOCGIFMTU, &ifr)) < 0) {
    perror("tunGetMtu: ioctl");
    return err;
  }
  *mtu = ifr.ifr_mtu;
  return 0;
}


x86 assembly (clang, -O0):
<tunGetMtu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1060 <interfaceIoctl@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11aa <tunGetMtu+0x6a>
lea    0xe66(%rip),%rdi
call   1050 <perror@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <tunGetMtu+0x7a>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tunGetMtu>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbp
mov    %rsp,%r15
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x4(%rsp),%edi
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rsi
call   1030 <strncpy@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
call   1060 <interfaceIoctl@plt>
test   %eax,%eax
js     119e <tunGetMtu+0x5e>
mov    (%rsp),%eax
mov    %eax,(%r14)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebp
lea    0xe59(%rip),%rdi
call   1050 <perror@plt>
mov    %ebp,%ebx
jmp    1191 <tunGetMtu+0x51>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
@IFNAMSIZ = global i32 0
@SIOCGIFMTU = global i32 0
@.str = [17 x i8] c"tunGetMtu: ioctl\00"
define i32 @tunGetMtu(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 @memset(%struct.ifreq* %6, i32 0, i32 8)
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 1
%10 = load i32, i32* %9
%11 = load i8*, i8** %4
%12 = load i32, i32* @IFNAMSIZ
%13 = call i32 @strncpy(i32 %10, i8* %11, i32 %12)
%14 = load i32, i32* @SIOCGIFMTU
%15 = call i32 @interfaceIoctl(i32 %14, %struct.ifreq* %6)
store i32 %15, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* %7
store i32 %19, i32* %3
br label %24
20: ; preds = %2
%21 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %6, i32 0, i32 0
%22 = load i32, i32* %21
%23 = load i32*, i32** %5
store i32 %22, i32* %23
store i32 0, i32* %3
br label %24
24: ; preds = %20, %17
%25 = load i32, i32* %3
ret i32 %25
}

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