#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 udev_device {
  int dummy;
};
struct udev {
  int dummy;
};
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ dev_t;

/* Variables and functions */
int major(int /*<<< orphan*/);
int minor(int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *, int,
                            int);
struct udev_device *udev_device_new_from_syspath(struct udev *, char *);
char *udev_get_sys_path(struct udev *);
__attribute__((visibility("default"))) struct udev_device *
udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum) {
  char path[1024];
  const char *type_str;
  if (type == 'b')
    type_str = "block";
  else if (type == 'c')
    type_str = "char";
  else
    return NULL;
  snprintf(path, sizeof(path), "%s/dev/%s/%u:%u", udev_get_sys_path(udev),
           type_str, major(devnum), minor(devnum));
  return udev_device_new_from_syspath(udev, path);
}


x86 assembly (clang, -O0):
<udev_device_new_from_devnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x62,%eax
jne    1188 <udev_device_new_from_devnum+0x38>
lea    0xe84(%rip),%rax
mov    %rax,-0x428(%rbp)
jmp    11ba <udev_device_new_from_devnum+0x6a>
movsbl -0x11(%rbp),%eax
cmp    $0x63,%eax
jne    11a8 <udev_device_new_from_devnum+0x58>
lea    0xe6a(%rip),%rax
mov    %rax,-0x428(%rbp)
jmp    11b5 <udev_device_new_from_devnum+0x65>
movq   $0x0,-0x8(%rbp)
jmp    1240 <udev_device_new_from_devnum+0xf0>
jmp    11ba <udev_device_new_from_devnum+0x6a>
lea    -0x420(%rbp),%rax
mov    %rax,-0x448(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <udev_get_sys_path@plt>
mov    %rax,-0x440(%rbp)
mov    -0x428(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <major@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <minor@plt>
mov    -0x448(%rbp),%rdi
mov    -0x440(%rbp),%rcx
mov    -0x438(%rbp),%r8
mov    -0x42c(%rbp),%r9d
mov    $0x400,%esi
lea    0xde7(%rip),%rdx
mov    %eax,(%rsp)
call   1050 <snprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1070 <udev_device_new_from_syspath@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udev_device_new_from_devnum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %edx,%ebp
mov    %rdi,%rbx
cmp    $0x62,%sil
je     1179 <udev_device_new_from_devnum+0x29>
cmp    $0x63,%sil
jne    11ce <udev_device_new_from_devnum+0x7e>
lea    0xe8f(%rip),%r14
jmp    1180 <udev_device_new_from_devnum+0x30>
lea    0xe80(%rip),%r14
mov    %rbx,%rdi
call   1030 <udev_get_sys_path@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1060 <major@plt>
mov    %eax,%r12d
mov    %ebp,%edi
call   1040 <minor@plt>
mov    %eax,(%rsp)
lea    0xe65(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %r14,%r8
mov    %r12d,%r9d
call   1050 <snprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <udev_device_new_from_syspath@plt>
jmp    11d0 <udev_device_new_from_devnum+0x80>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
@.str = [6 x i8] c"block\00"
@.str.1 = [5 x i8] c"char\00"
@.str.2 = [16 x i8] c"%s/dev/%s/%u:%u\00"
define %struct.udev_device* @udev_device_new_from_devnum(%struct.udev* %0, i8 signext %1, i32 %2) {
%4 = alloca %struct.udev_device*
%5 = alloca %struct.udev*
%6 = alloca i8
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i8*
store %struct.udev* %0, %struct.udev** %5
store i8 %1, i8* %6
store i32 %2, i32* %7
%10 = load i8, i8* %6
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 98
br i1 %12, label %13, label %14
13: ; preds = %3
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %9
br label %21
14: ; preds = %3
%15 = load i8, i8* %6
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 99
br i1 %17, label %18, label %19
18: ; preds = %14
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %20
19: ; preds = %14
store %struct.udev_device* null, %struct.udev_device** %4
br label %34
20: ; preds = %18
br label %21
21: ; preds = %20, %13
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%23 = load %struct.udev*, %struct.udev** %5
%24 = call i8* @udev_get_sys_path(%struct.udev* %23)
%25 = load i8*, i8** %9
%26 = load i32, i32* %7
%27 = call i32 @major(i32 %26)
%28 = load i32, i32* %7
%29 = call i32 @minor(i32 %28)
%30 = call i32 @snprintf(i8* %22, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %25, i32 %27, i32 %29)
%31 = load %struct.udev*, %struct.udev** %5
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%33 = call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %31, i8* %32)
store %struct.udev_device* %33, %struct.udev_device** %4
br label %34
34: ; preds = %21, %19
%35 = load %struct.udev_device*, %struct.udev_device** %4
ret %struct.udev_device* %35
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
%struct.udev = type { i32 }
@.str = [6 x i8] c"block\00"
@.str.1 = [5 x i8] c"char\00"
@.str.2 = [16 x i8] c"%s/dev/%s/%u:%u\00"
define %struct.udev_device* @udev_device_new_from_devnum(%struct.udev* %0, i8 signext %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
switch i8 %1, label %14 [
i8 98, label %7
i8 99, label %6
]
6: ; preds = %3
br label %7
7: ; preds = %3, %6
%8 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %3 ]
%9 = tail call i8* @udev_get_sys_path(%struct.udev* %0)
%10 = tail call i32 @major(i32 %2)
%11 = tail call i32 @minor(i32 %2)
%12 = call i32 @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %8, i32 %10, i32 %11)
%13 = call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %0, i8* %5)
br label %14
14: ; preds = %3, %7
%15 = phi %struct.udev_device* [ %13, %7 ], [ null, %3 ]
ret %struct.udev_device* %15
}