#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 /*<<< orphan*/ ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
size_t IFNAMSIZ;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, int, size_t);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char const *, size_t);
struct ifreq get_ifreq(const char *interface) {
  struct ifreq ifr;
  size_t if_len;
  memset(ifr.ifr_name, 0x00, IFNAMSIZ);
  if_len = strlen(interface);
  if (if_len >= IFNAMSIZ) {
    fprintf(stderr, "Interface name too long to open descriptor.\nAbort.");
    exit(EXIT_FAILURE);
  }
  strncpy(ifr.ifr_name, interface, if_len);
  return ifr;
}


x86 assembly (clang, -O0):
<get_ifreq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e72(%rip),%rax
mov    (%rax),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%rax
jb     11b4 <get_ifreq+0x64>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ifreq>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e7a(%rip),%r14
mov    (%r14),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    (%r14),%rax
jae    1187 <get_ifreq+0x37>
mov    %rbx,%rsi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strncpy@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32 }
@IFNAMSIZ = global i64 0
@stderr = global i32 0
@.str = [51 x i8] c"Interface name too long to open descriptor.\0AAbort.\00"
@EXIT_FAILURE = global i32 0
define i32 @get_ifreq(i8* %0) {
%2 = alloca %struct.ifreq
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
%5 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 0
%6 = load i32, i32* %5
%7 = load i64, i64* @IFNAMSIZ
%8 = call i32 @memset(i32 %6, i32 0, i64 %7)
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = load i64, i64* @IFNAMSIZ
%13 = icmp uge i64 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %1
%20 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i8*, i8** %3
%23 = load i64, i64* %4
%24 = call i32 @strncpy(i32 %21, i8* %22, i64 %23)
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i32 0, i32 0
%26 = load i32, i32* %25
ret i32 %26
}

LLVM IR (-O2):
@IFNAMSIZ = global i64 0
@stderr = global i32 0
@.str = [51 x i8] c"Interface name too long to open descriptor.\0AAbort.\00"
@EXIT_FAILURE = global i32 0
define i32 @get_ifreq(i8* %0) {
%2 = load i64, i64* @IFNAMSIZ
%3 = tail call i32 @memset(i32 undef, i32 0, i64 %2)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = load i64, i64* @IFNAMSIZ
%6 = icmp ult i64 %4, %5
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = tail call i32 @strncpy(i32 undef, i8* %0, i64 %4)
ret i32 undef
}