#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 {
  scalar_t__ *ifr_name;
};

/* Variables and functions */
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ memcpy(scalar_t__ *, char const *, size_t);
size_t strlen(char const *);
void set_ifr_name(struct ifreq *ifr, const char *if_name) {
  size_t if_name_len = strlen(if_name);
  if (if_name_len < sizeof(ifr->ifr_name)) {
    memcpy(ifr->ifr_name, if_name, if_name_len);
    ifr->ifr_name[if_name_len] = 0;
  } else {
    die("Interface name is too long");
  }
}


x86 assembly (clang, -O0):
<set_ifr_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x8,-0x18(%rbp)
jae    1184 <set_ifr_name+0x54>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    1190 <set_ifr_name+0x60>
lea    0xe75(%rip),%rdi
call   1050 <die@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_ifr_name>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    $0x7,%rax
ja     116b <set_ifr_name+0x3b>
mov    %rax,%rbx
mov    (%r14),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1040 <memcpy@plt>
mov    (%r14),%rax
movq   $0x0,(%rax,%rbx,8)
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe8e(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <die@plt>

LLVM IR (-O0):
%struct.ifreq = type { i64* }
@.str = [27 x i8] c"Interface name is too long\00"
define void @set_ifr_name(%struct.ifreq* %0, i8* %1) {
%3 = alloca %struct.ifreq*
%4 = alloca i8*
%5 = alloca i64
store %struct.ifreq* %0, %struct.ifreq** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp ult i64 %8, 8
br i1 %9, label %10, label %22
10: ; preds = %2
%11 = load %struct.ifreq*, %struct.ifreq** %3
%12 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %11, i32 0, i32 0
%13 = load i64*, i64** %12
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = call i32 @memcpy(i64* %13, i8* %14, i64 %15)
%17 = load %struct.ifreq*, %struct.ifreq** %3
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %17, i32 0, i32 0
%19 = load i64*, i64** %18
%20 = load i64, i64* %5
%21 = getelementptr inbounds i64, i64* %19, i64 %20
store i64 0, i64* %21
br label %24
22: ; preds = %2
%23 = call i32 @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %10
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i64* }
@.str = [27 x i8] c"Interface name is too long\00"
define void @set_ifr_name(%struct.ifreq* nocapture %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp ult i64 %3, 8
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %0, i64 0, i32 0
%7 = load i64*, i64** %6
%8 = tail call i32 @memcpy(i64* %7, i8* %1, i64 %3)
%9 = load i64*, i64** %6
%10 = getelementptr inbounds i64, i64* %9, i64 %3
store i64 0, i64* %10
br label %13
11: ; preds = %2
%12 = tail call i32 @die(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %5
ret void
}