#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 {
  char *ifr_name;
  char *ifr_newname;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
int open(char *, int /*<<< orphan*/);
void rename_netif_kernel_log(struct ifreq ifr) {
  int klog;
  FILE *f;
  klog = open("/dev/kmsg", O_WRONLY);
  if (klog < 0)
    return;
  f = fdopen(klog, "w");
  if (f == NULL) {
    close(klog);
    return;
  }
  fprintf(f, "<6>udev: renamed network interface %s to %s\n", ifr.ifr_name,
          ifr.ifr_newname);
  fclose(f);
}


x86 assembly (clang, -O0):
<rename_netif_kernel_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
lea    0xe90(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1187 <rename_netif_kernel_log+0x37>
jmp    11d3 <rename_netif_kernel_log+0x83>
mov    -0x14(%rbp),%edi
lea    0xe79(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b2 <rename_netif_kernel_log+0x62>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    11d3 <rename_netif_kernel_log+0x83>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe47(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rename_netif_kernel_log>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
lea    0xe93(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11b5 <rename_netif_kernel_log+0x65>
mov    %eax,%ebp
lea    0xe8b(%rip),%rsi
mov    %eax,%edi
call   1060 <fdopen@plt>
test   %rax,%rax
je     11c0 <rename_netif_kernel_log+0x70>
mov    %rax,%rbx
lea    0xe77(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>

LLVM IR (-O0):
%struct.ifreq = type { i8*, i8* }
@.str = [10 x i8] c"/dev/kmsg\00"
@O_WRONLY = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [45 x i8] c"<6>udev: renamed network interface %s to %s\0A\00"
define void @rename_netif_kernel_log(i8* %0, i8* %1) {
%3 = alloca %struct.ifreq
%4 = alloca i32
%5 = alloca i32*
%6 = bitcast %struct.ifreq* %3 to { i8*, i8* }*
%7 = getelementptr inbounds { i8*, i8* }, { i8*, i8* }* %6, i32 0, i32 0
store i8* %0, i8** %7
%8 = getelementptr inbounds { i8*, i8* }, { i8*, i8* }* %6, i32 0, i32 1
store i8* %1, i8** %8
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
br label %31
14: ; preds = %2
%15 = load i32, i32* %4
%16 = call i32* @fdopen(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %5
%17 = load i32*, i32** %5
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* %4
%21 = call i32 @close(i32 %20)
br label %31
22: ; preds = %14
%23 = load i32*, i32** %5
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 1
%27 = load i8*, i8** %26
%28 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %25, i8* %27)
%29 = load i32*, i32** %5
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %22, %19, %13
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/kmsg\00"
@O_WRONLY = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [45 x i8] c"<6>udev: renamed network interface %s to %s\0A\00"
define void @rename_netif_kernel_log(i8* %0, i8* %1) {
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = tail call i32* @fdopen(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @close(i32 %4)
br label %14
11: ; preds = %6
%12 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
%13 = tail call i32 @fclose(i32* %7)
br label %14
14: ; preds = %2, %11, %9
ret void
}