#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*/ AF_INET;
int EXIT_FAILURE;
int /*<<< orphan*/ IPPROTO_RAW;
int /*<<< orphan*/ SIOCGIFMTU;
int /*<<< orphan*/ SOCK_RAW;
scalar_t__ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ snprintf(int /*<<< orphan*/, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sd;
  char interface[] = "eth0";
  struct ifreq ifr;
  if ((sd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
    perror("socket() ");
    exit(EXIT_FAILURE);
  }
  memset(&ifr, 0, sizeof(struct ifreq));
  snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", interface);
  if (ioctl(sd, SIOCGIFMTU, &ifr) < 0) {
    perror("ioctl() failed to find interface MTU ");
    return (EXIT_FAILURE);
  }
  printf("MTU for interface %s is %d\n", interface, ifr.ifr_mtu);
  if (close(sd) < 0)
    perror("close() ");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe64(%rip),%eax
mov    %eax,-0x19(%rbp)
mov    0xe5f(%rip),%al
mov    %al,-0x15(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11ee <main+0x6e>
lea    0xe2a(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x24(%rbp),%edi
lea    -0x19(%rbp),%rcx
mov    $0x4,%esi
lea    0xdfe(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x14(%rbp),%edi
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    1252 <main+0xd2>
lea    0xdd6(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1283 <main+0x103>
lea    -0x19(%rbp),%rsi
mov    -0x28(%rbp),%edx
lea    0xdd8(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
cmp    $0x0,%rax
jge    1283 <main+0x103>
lea    0xdd6(%rip),%rdi
call   1080 <perror@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0x4(%rsp)
movl   $0x30687465,(%rsp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
test   %eax,%eax
js     1256 <main+0xd6>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0xc(%rsp),%edi
lea    0xe2f(%rip),%rdx
mov    %rsp,%rcx
mov    $0x4,%esi
call   1040 <snprintf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
js     1230 <main+0xb0>
mov    0x8(%rsp),%edx
lea    0xe28(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
test   %rax,%rax
js     1248 <main+0xc8>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xddb(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%r14d
jmp    1224 <main+0xa4>
lea    0xe05(%rip),%rdi
call   1080 <perror@plt>
jmp    1224 <main+0xa4>
lea    0xda8(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
@__const.main.interface = [5 x i8] c"eth0\00"
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@.str = [10 x i8] c"socket() \00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@SIOCGIFMTU = global i32 0
@.str.2 = [38 x i8] c"ioctl() failed to find interface MTU \00"
@.str.3 = [28 x i8] c"MTU for interface %s is %d\0A\00"
@.str.4 = [9 x i8] c"close() \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [5 x i8]
%8 = alloca %struct.ifreq
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [5 x i8]* %7 to i8*
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_RAW
%12 = load i32, i32* @IPPROTO_RAW
%13 = call i32 @socket(i32 %10, i32 %11, i32 %12)
store i32 %13, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = call i32 @memset(%struct.ifreq* %8, i32 0, i32 8)
%21 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%24 = call i32 @snprintf(i32 %22, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %6
%26 = load i32, i32* @SIOCGIFMTU
%27 = call i64 @ioctl(i32 %25, i32 %26, %struct.ifreq* %8)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %19
%30 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %3
br label %42
32: ; preds = %19
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%34 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %33, i32 %35)
%37 = load i32, i32* %6
%38 = call i64 @close(i32 %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %29, %40, %32
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@__const.main.interface = [5 x i8] c"eth0\00"
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@.str = [10 x i8] c"socket() \00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@SIOCGIFMTU = global i32 0
@.str.2 = [38 x i8] c"ioctl() failed to find interface MTU \00"
@.str.3 = [28 x i8] c"MTU for interface %s is %d\0A\00"
@.str.4 = [9 x i8] c"close() \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [5 x i8]
%4 = alloca %struct.ifreq
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.ifreq* %4 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_RAW
%9 = load i32, i32* @IPPROTO_RAW
%10 = tail call i32 @socket(i32 %7, i32 %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = call i32 @memset(%struct.ifreq* %4, i32 0, i32 8)
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 1
%19 = load i32, i32* %18
%20 = call i32 @snprintf(i32 %19, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%21 = load i32, i32* @SIOCGIFMTU
%22 = call i64 @ioctl(i32 %10, i32 %21, %struct.ifreq* %4)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
br label %35
27: ; preds = %16
%28 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %5, i32 %29)
%31 = call i64 @close(i32 %10)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %27, %33, %24
%36 = phi i32 [ %26, %24 ], [ 0, %33 ], [ 0, %27 ]
ret i32 %36
}