#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 *, int, char *, char *);
int getpid();
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, "<30>udevd[%u]: renamed network interface %s to %s\n", getpid(),
          ifr.ifr_name, ifr.ifr_newname);
  fclose(f);
}


x86 assembly (clang, -O0):
<rename_netif_kernel_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe80(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1197 <rename_netif_kernel_log+0x37>
jmp    11f4 <rename_netif_kernel_log+0x94>
mov    -0x14(%rbp),%edi
lea    0xe69(%rip),%rsi
call   1070 <fdopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c2 <rename_netif_kernel_log+0x62>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    11f4 <rename_netif_kernel_log+0x94>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xe26(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%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    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11ce <rename_netif_kernel_log+0x6e>
mov    %eax,%ebp
lea    0xe7b(%rip),%rsi
mov    %eax,%edi
call   1070 <fdopen@plt>
test   %rax,%rax
je     11d9 <rename_netif_kernel_log+0x79>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <fprintf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <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    1050 <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 = [51 x i8] c"<30>udevd[%u]: 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 %32
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 %32
22: ; preds = %14
%23 = load i32*, i32** %5
%24 = call i32 (...) @getpid()
%25 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %3, i32 0, i32 1
%28 = load i8*, i8** %27
%29 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %24, i8* %26, i8* %28)
%30 = load i32*, i32** %5
%31 = call i32 @fclose(i32* %30)
br label %32
32: ; 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 = [51 x i8] c"<30>udevd[%u]: 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 %15, 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 %15
11: ; preds = %6
%12 = tail call i32 (...) @getpid()
%13 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %12, i8* %0, i8* %1)
%14 = tail call i32 @fclose(i32* %7)
br label %15
15: ; preds = %2, %11, %9
ret void
}