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

/* Variables and functions */
int /*<<< orphan*/ SIOCGIFMTU;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char const *);
unsigned int get_device_mtu(int fd, const char *ifname) {
  struct ifreq ifr;
  memset(&ifr, 0, sizeof(ifr));
  strcpy(ifr.ifr_name, ifname);
  if (ioctl(fd, SIOCGIFMTU, &ifr))
    error(1, errno, "ioctl get mtu");
  return ifr.ifr_mtu;
}


x86 assembly (clang, -O0):
<get_device_mtu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     11a4 <get_device_mtu+0x64>
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe61(%rip),%rdx
call   1060 <error@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_device_mtu>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
je     119f <get_device_mtu+0x5f>
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdx
mov    $0x1,%edi
call   1060 <error@plt>
mov    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
@SIOCGIFMTU = global i32 0
@errno = global i32 0
@.str = [14 x i8] c"ioctl get mtu\00"
define i32 @get_device_mtu(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.ifreq
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = call i32 @memset(%struct.ifreq* %5, i32 0, i32 8)
%7 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 1
%8 = load i32, i32* %7
%9 = load i8*, i8** %4
%10 = call i32 @strcpy(i32 %8, i8* %9)
%11 = load i32, i32* %3
%12 = load i32, i32* @SIOCGIFMTU
%13 = call i64 @ioctl(i32 %11, i32 %12, %struct.ifreq* %5)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @errno
%17 = call i32 @error(i32 1, i32 %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %15, %2
%19 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 0
%20 = load i32, i32* %19
ret i32 %20
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@SIOCGIFMTU = global i32 0
@errno = global i32 0
@.str = [14 x i8] c"ioctl get mtu\00"
define i32 @get_device_mtu(i32 %0, i8* %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 = call i32 @strcpy(i32 %7, i8* %1)
%9 = load i32, i32* @SIOCGIFMTU
%10 = call i64 @ioctl(i32 %0, i32 %9, %struct.ifreq* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @errno
%14 = call i32 @error(i32 1, i32 %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %12, %2
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i64 0, i32 0
%17 = load i32, i32* %16
ret i32 %17
}