#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 chmod(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *replace_key_by_value(int /*<<< orphan*/, struct hotplug2_event_t *);
int /*<<< orphan*/ strdup(char *);
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/, int);
int chmod_file(struct hotplug2_event_t *event, char *file, char *value) {
  int rv;
  file = replace_key_by_value(strdup(file), event);
  value = replace_key_by_value(strdup(value), event);
  rv = chmod(file, strtoul(value, 0, 8));
  free(file);
  free(value);
  return rv;
}


x86 assembly (clang, -O0):
<chmod_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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   1040 <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   1040 <replace_key_by_value@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <strtoul@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1050 <chmod@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    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chmod_file>:
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   1040 <replace_key_by_value@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <strdup@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <replace_key_by_value@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <strtoul@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <chmod@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 @chmod_file(%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** %5
%17 = load i8*, i8** %6
%18 = call i32 @strtoul(i8* %17, i32 0, i32 8)
%19 = call i32 @chmod(i8* %16, i32 %18)
store i32 %19, i32* %7
%20 = load i8*, i8** %5
%21 = call i32 @free(i8* %20)
%22 = load i8*, i8** %6
%23 = call i32 @free(i8* %22)
%24 = load i32, i32* %7
ret i32 %24
}

LLVM IR (-O2):
%struct.hotplug2_event_t = type { i32 }
define i32 @chmod_file(%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 @strtoul(i8* %7, i32 0, i32 8)
%9 = tail call i32 @chmod(i8* %5, i32 %8)
%10 = tail call i32 @free(i8* %5)
%11 = tail call i32 @free(i8* %7)
ret i32 %9
}