#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 const *, int, int);
struct udev_device *udev_device_new_from_syspath(struct udev *, char *);
__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), "/sys/dev/%s/%u:%u", 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    $0x440,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x62,%eax
jne    1178 <udev_device_new_from_devnum+0x38>
lea    0xe94(%rip),%rax
mov    %rax,-0x428(%rbp)
jmp    11aa <udev_device_new_from_devnum+0x6a>
movsbl -0x11(%rbp),%eax
cmp    $0x63,%eax
jne    1198 <udev_device_new_from_devnum+0x58>
lea    0xe7a(%rip),%rax
mov    %rax,-0x428(%rbp)
jmp    11a5 <udev_device_new_from_devnum+0x65>
movq   $0x0,-0x8(%rbp)
jmp    1219 <udev_device_new_from_devnum+0xd9>
jmp    11aa <udev_device_new_from_devnum+0x6a>
lea    -0x420(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x428(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <major@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <minor@plt>
mov    -0x440(%rbp),%rdi
mov    -0x438(%rbp),%rcx
mov    -0x42c(%rbp),%r8d
mov    %eax,%r9d
mov    $0x400,%esi
lea    0xe0b(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1060 <udev_device_new_from_syspath@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udev_device_new_from_devnum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edx,%ebp
mov    %rdi,%r14
cmp    $0x62,%sil
je     1167 <udev_device_new_from_devnum+0x27>
cmp    $0x63,%sil
jne    11ab <udev_device_new_from_devnum+0x6b>
lea    0xea1(%rip),%r15
jmp    116e <udev_device_new_from_devnum+0x2e>
lea    0xe92(%rip),%r15
mov    %ebp,%edi
call   1050 <major@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <minor@plt>
lea    0xe86(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %ebx,%r8d
mov    %eax,%r9d
call   1040 <snprintf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <udev_device_new_from_syspath@plt>
jmp    11ad <udev_device_new_from_devnum+0x6d>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
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 = [18 x i8] c"/sys/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 %32
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 i8*, i8** %9
%24 = load i32, i32* %7
%25 = call i32 @major(i32 %24)
%26 = load i32, i32* %7
%27 = call i32 @minor(i32 %26)
%28 = call i32 @snprintf(i8* %22, i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %23, i32 %25, i32 %27)
%29 = load %struct.udev*, %struct.udev** %5
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%31 = call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %29, i8* %30)
store %struct.udev_device* %31, %struct.udev_device** %4
br label %32
32: ; preds = %21, %19
%33 = load %struct.udev_device*, %struct.udev_device** %4
ret %struct.udev_device* %33
}

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 = [18 x i8] c"/sys/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 %13 [
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 i32 @major(i32 %2)
%10 = tail call i32 @minor(i32 %2)
%11 = call i32 @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %8, i32 %9, i32 %10)
%12 = call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %0, i8* %5)
br label %13
13: ; preds = %3, %7
%14 = phi %struct.udev_device* [ %12, %7 ], [ null, %3 ]
ret %struct.udev_device* %14
}