#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;
};
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
int /*<<< orphan*/ S_IFBLK;
int /*<<< orphan*/ S_IFCHR;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ chmod(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *get_hotplug2_value_by_key(struct hotplug2_event_t *, char *);
int /*<<< orphan*/ makedev(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mkdir_p(char *);
int mknod(char *, int /*<<< orphan*/, int /*<<< orphan*/);
char *replace_key_by_value(char *, struct hotplug2_event_t *);
int /*<<< orphan*/ strcmp(char *, char *);
int make_dev_from_event(struct hotplug2_event_t *event, char *path,
                        mode_t devmode) {
  char *subsystem, *major, *minor, *devpath;
  int rv = 1;
  major = get_hotplug2_value_by_key(event, "MAJOR");
  if (major == NULL)
    goto return_value;
  minor = get_hotplug2_value_by_key(event, "MINOR");
  if (minor == NULL)
    goto return_value;
  devpath = get_hotplug2_value_by_key(event, "DEVPATH");
  if (devpath == NULL)
    goto return_value;
  subsystem = get_hotplug2_value_by_key(event, "SUBSYSTEM");
  if (!strcmp(subsystem, "block"))
    devmode |= S_IFBLK;
  else
    devmode |= S_IFCHR;
  path = replace_key_by_value(path, event);
  mkdir_p(path);
  rv = mknod(path, devmode, makedev(atoi(major), atoi(minor)));
  chmod(path, devmode);
  free(path);
return_value:
  return rv;
}


x86 assembly (clang, -O0):
<make_dev_from_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1080 <get_hotplug2_value_by_key@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ce <make_dev_from_event+0x3e>
jmp    12d3 <make_dev_from_event+0x143>
mov    -0x8(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1080 <get_hotplug2_value_by_key@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f2 <make_dev_from_event+0x62>
jmp    12d3 <make_dev_from_event+0x143>
mov    -0x8(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1080 <get_hotplug2_value_by_key@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1216 <make_dev_from_event+0x86>
jmp    12d3 <make_dev_from_event+0x143>
mov    -0x8(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   1080 <get_hotplug2_value_by_key@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1257 <make_dev_from_event+0xc7>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1266 <make_dev_from_event+0xd6>
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <replace_key_by_value@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <mkdir_p@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%rdi
call   10b0 <atoi@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%esi
call   10a0 <makedev@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    %eax,%edx
call   1050 <mknod@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1090 <chmod@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_dev_from_event>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xe58(%rip),%rsi
call   1080 <get_hotplug2_value_by_key@plt>
test   %rax,%rax
je     120b <make_dev_from_event+0x7b>
mov    %rax,%rbx
lea    0xe4a(%rip),%rsi
mov    %rbp,%rdi
call   1080 <get_hotplug2_value_by_key@plt>
test   %rax,%rax
je     120b <make_dev_from_event+0x7b>
mov    %rax,%r12
lea    0xe39(%rip),%rsi
mov    %rbp,%rdi
call   1080 <get_hotplug2_value_by_key@plt>
test   %rax,%rax
je     120b <make_dev_from_event+0x7b>
lea    0xe2d(%rip),%rsi
mov    %rbp,%rdi
call   1080 <get_hotplug2_value_by_key@plt>
lea    0xe28(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    1212 <make_dev_from_event+0x82>
mov    0x2dd7(%rip),%rax
jmp    1219 <make_dev_from_event+0x89>
mov    $0x1,%eax
jmp    1271 <make_dev_from_event+0xe1>
mov    0x2dbf(%rip),%rax
or     (%rax),%r14d
mov    %r15,%rdi
mov    %rbp,%rsi
call   1070 <replace_key_by_value@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <mkdir_p@plt>
mov    %rbx,%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   10b0 <atoi@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   10a0 <makedev@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %eax,%edx
call   1050 <mknod@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
mov    %r14d,%esi
call   1090 <chmod@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hotplug2_event_t = type { i32 }
@.str = [6 x i8] c"MAJOR\00"
@.str.1 = [6 x i8] c"MINOR\00"
@.str.2 = [8 x i8] c"DEVPATH\00"
@.str.3 = [10 x i8] c"SUBSYSTEM\00"
@.str.4 = [6 x i8] c"block\00"
@S_IFBLK = global i32 0
@S_IFCHR = global i32 0
define i32 @make_dev_from_event(%struct.hotplug2_event_t* %0, i8* %1, i32 %2) {
%4 = alloca %struct.hotplug2_event_t*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store %struct.hotplug2_event_t* %0, %struct.hotplug2_event_t** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 1, i32* %11
%12 = load %struct.hotplug2_event_t*, %struct.hotplug2_event_t** %4
%13 = call i8* @get_hotplug2_value_by_key(%struct.hotplug2_event_t* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %3
br label %62
17: ; preds = %3
%18 = load %struct.hotplug2_event_t*, %struct.hotplug2_event_t** %4
%19 = call i8* @get_hotplug2_value_by_key(%struct.hotplug2_event_t* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
br label %62
23: ; preds = %17
%24 = load %struct.hotplug2_event_t*, %struct.hotplug2_event_t** %4
%25 = call i8* @get_hotplug2_value_by_key(%struct.hotplug2_event_t* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %25, i8** %10
%26 = load i8*, i8** %10
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %23
br label %62
29: ; preds = %23
%30 = load %struct.hotplug2_event_t*, %struct.hotplug2_event_t** %4
%31 = call i8* @get_hotplug2_value_by_key(%struct.hotplug2_event_t* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i8* %31, i8** %7
%32 = load i8*, i8** %7
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %29
%36 = load i32, i32* @S_IFBLK
%37 = load i32, i32* %6
%38 = or i32 %37, %36
store i32 %38, i32* %6
br label %43
39: ; preds = %29
%40 = load i32, i32* @S_IFCHR
%41 = load i32, i32* %6
%42 = or i32 %41, %40
store i32 %42, i32* %6
br label %43
43: ; preds = %39, %35
%44 = load i8*, i8** %5
%45 = load %struct.hotplug2_event_t*, %struct.hotplug2_event_t** %4
%46 = call i8* @replace_key_by_value(i8* %44, %struct.hotplug2_event_t* %45)
store i8* %46, i8** %5
%47 = load i8*, i8** %5
%48 = call i32 @mkdir_p(i8* %47)
%49 = load i8*, i8** %5
%50 = load i32, i32* %6
%51 = load i8*, i8** %8
%52 = call i32 @atoi(i8* %51)
%53 = load i8*, i8** %9
%54 = call i32 @atoi(i8* %53)
%55 = call i32 @makedev(i32 %52, i32 %54)
%56 = call i32 @mknod(i8* %49, i32 %50, i32 %55)
store i32 %56, i32* %11
%57 = load i8*, i8** %5
%58 = load i32, i32* %6
%59 = call i32 @chmod(i8* %57, i32 %58)
%60 = load i8*, i8** %5
%61 = call i32 @free(i8* %60)
br label %62
62: ; preds = %43, %28, %22, %16
%63 = load i32, i32* %11
ret i32 %63
}

LLVM IR (-O2):
%struct.hotplug2_event_t = type { i32 }
@.str = [6 x i8] c"MAJOR\00"
@.str.1 = [6 x i8] c"MINOR\00"
@.str.2 = [8 x i8] c"DEVPATH\00"
@.str.3 = [10 x i8] c"SUBSYSTEM\00"
@.str.4 = [6 x i8] c"block\00"
@S_IFBLK = global i32 0
@S_IFCHR = global i32 0
define i32 @make_dev_from_event(%struct.hotplug2_event_t* %0, i8* %1, i32 %2) {
%4 = tail call i8* @get_hotplug2_value_by_key(%struct.hotplug2_event_t* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %28, label %6
6: ; preds = %3
%7 = tail call i8* @get_hotplug2_value_by_key(%struct.hotplug2_event_t* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %28, label %9
9: ; preds = %6
%10 = tail call i8* @get_hotplug2_value_by_key(%struct.hotplug2_event_t* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %28, label %12
12: ; preds = %9
%13 = tail call i8* @get_hotplug2_value_by_key(%struct.hotplug2_event_t* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %13, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%15 = icmp eq i32 %14, 0
%16 = load i32, i32* @S_IFBLK
%17 = load i32, i32* @S_IFCHR
%18 = select i1 %15, i32 %16, i32 %17
%19 = or i32 %18, %2
%20 = tail call i8* @replace_key_by_value(i8* %1, %struct.hotplug2_event_t* %0)
%21 = tail call i32 @mkdir_p(i8* %20)
%22 = tail call i32 @atoi(i8* %4)
%23 = tail call i32 @atoi(i8* %7)
%24 = tail call i32 @makedev(i32 %22, i32 %23)
%25 = tail call i32 @mknod(i8* %20, i32 %19, i32 %24)
%26 = tail call i32 @chmod(i8* %20, i32 %19)
%27 = tail call i32 @free(i8* %20)
br label %28
28: ; preds = %9, %6, %3, %12
%29 = phi i32 [ 1, %3 ], [ 1, %6 ], [ 1, %9 ], [ %25, %12 ]
ret i32 %29
}