#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 hotplug2_event_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ mkdir_p(char *);
char *replace_key_by_value(int /*<<< orphan*/, struct hotplug2_event_t *);
int /*<<< orphan*/ strdup(char *);
int symlink(char *, char *);
int make_symlink(struct hotplug2_event_t *event, char *target, char *linkname) {
  int rv;
  target = replace_key_by_value(strdup(target), event);
  linkname = replace_key_by_value(strdup(linkname), event);
  mkdir_p(linkname);
  rv = symlink(target, linkname);
  free(target);
  free(linkname);
  return rv;
}


x86 assembly (clang, -O0):
<make_symlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%rsi
call   1060 <replace_key_by_value@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <strdup@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%rsi
call   1060 <replace_key_by_value@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <mkdir_p@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <symlink@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_symlink>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1070 <strdup@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <replace_key_by_value@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <strdup@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <replace_key_by_value@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <mkdir_p@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <symlink@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hotplug2_event_t = type { i32 }
define i32 @make_symlink(%struct.hotplug2_event_t* %0, i8* %1, i8* %2) {
%4 = alloca %struct.hotplug2_event_t*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store %struct.hotplug2_event_t* %0, %struct.hotplug2_event_t** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %5
%9 = call i32 @strdup(i8* %8)
%10 = load %struct.hotplug2_event_t*, %struct.hotplug2_event_t** %4
%11 = call i8* @replace_key_by_value(i32 %9, %struct.hotplug2_event_t* %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %6
%13 = call i32 @strdup(i8* %12)
%14 = load %struct.hotplug2_event_t*, %struct.hotplug2_event_t** %4
%15 = call i8* @replace_key_by_value(i32 %13, %struct.hotplug2_event_t* %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = call i32 @mkdir_p(i8* %16)
%18 = load i8*, i8** %5
%19 = load i8*, i8** %6
%20 = call i32 @symlink(i8* %18, i8* %19)
store i32 %20, i32* %7
%21 = load i8*, i8** %5
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %6
%24 = call i32 @free(i8* %23)
%25 = load i32, i32* %7
ret i32 %25
}

LLVM IR (-O2):
%struct.hotplug2_event_t = type { i32 }
define i32 @make_symlink(%struct.hotplug2_event_t* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strdup(i8* %1)
%5 = tail call i8* @replace_key_by_value(i32 %4, %struct.hotplug2_event_t* %0)
%6 = tail call i32 @strdup(i8* %2)
%7 = tail call i8* @replace_key_by_value(i32 %6, %struct.hotplug2_event_t* %0)
%8 = tail call i32 @mkdir_p(i8* %7)
%9 = tail call i32 @symlink(i8* %5, i8* %7)
%10 = tail call i32 @free(i8* %5)
%11 = tail call i32 @free(i8* %7)
ret i32 %9
}