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

/* Variables and functions */
int /*<<< orphan*/ bb_perror_msg_and_die(char *);
int /*<<< orphan*/ close(int);
int get_ctl_fd();
int ioctl(int, int, struct ifreq *);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
void do_changename(char *dev, char *newdev) {
  struct ifreq ifr;
  int fd;
  int err;
  strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
  strncpy(ifr.ifr_newname, newdev, sizeof(ifr.ifr_newname));
  fd = get_ctl_fd();
  err = ioctl(fd, 0x8923, &ifr);
  if (err) {
    bb_perror_msg_and_die("SIOCSIFNAME");
  }
  close(fd);
}


x86 assembly (clang, -O0):
<do_changename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    $0x0,%al
call   1070 <get_ctl_fd@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x8923,%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11b6 <do_changename+0x66>
lea    0xe4f(%rip),%rdi
call   1060 <bb_perror_msg_and_die@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_changename>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
call   1070 <get_ctl_fd@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rdx
mov    %eax,%edi
mov    $0x8923,%esi
call   1040 <ioctl@plt>
test   %eax,%eax
je     119c <do_changename+0x4c>
lea    0xe69(%rip),%rdi
call   1060 <bb_perror_msg_and_die@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
@.str = [12 x i8] c"SIOCSIFNAME\00"
define void @do_changename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.ifreq
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 1
%9 = load i32, i32* %8
%10 = load i8*, i8** %3
%11 = call i32 @strncpy(i32 %9, i8* %10, i32 4)
%12 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %5, i32 0, i32 0
%13 = load i32, i32* %12
%14 = load i8*, i8** %4
%15 = call i32 @strncpy(i32 %13, i8* %14, i32 4)
%16 = call i32 (...) @get_ctl_fd()
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = call i32 @ioctl(i32 %17, i32 35107, %struct.ifreq* %5)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @bb_perror_msg_and_die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %2
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@.str = [12 x i8] c"SIOCSIFNAME\00"
define void @do_changename(i8* %0, i8* %1) {
%3 = alloca %struct.ifreq
%4 = bitcast %struct.ifreq* %3 to i8*
%5 = tail call i32 @strncpy(i32 undef, i8* %0, i32 4)
%6 = tail call i32 @strncpy(i32 undef, i8* %1, i32 4)
%7 = tail call i32 (...) @get_ctl_fd()
%8 = call i32 @ioctl(i32 %7, i32 35107, %struct.ifreq* %3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 @bb_perror_msg_and_die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = call i32 @close(i32 %7)
ret void
}