#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 /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ errno;
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 *);
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 {
    errno = EINVAL;
    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    11bc <udev_device_new_from_devnum+0x7c>
movsbl -0x11(%rbp),%eax
cmp    $0x63,%eax
jne    1198 <udev_device_new_from_devnum+0x58>
lea    0xe7a(%rip),%rax
mov    %rax,-0x428(%rbp)
jmp    11b7 <udev_device_new_from_devnum+0x77>
mov    0x2e39(%rip),%rax
mov    (%rax),%ecx
mov    0x2e38(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    122b <udev_device_new_from_devnum+0xeb>
jmp    11bc <udev_device_new_from_devnum+0x7c>
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    0xdf9(%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    11bf <udev_device_new_from_devnum+0x7f>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    0x2e25(%rip),%rcx
mov    %eax,(%rcx)
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"
@EINVAL = global i32 0
@errno = global i32 0
@.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 %22
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 %21
19: ; preds = %14
%20 = load i32, i32* @EINVAL
store i32 %20, i32* @errno
store %struct.udev_device* null, %struct.udev_device** %4
br label %33
21: ; preds = %18
br label %22
22: ; preds = %21, %13
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%24 = load i8*, i8** %9
%25 = load i32, i32* %7
%26 = call i32 @major(i32 %25)
%27 = load i32, i32* %7
%28 = call i32 @minor(i32 %27)
%29 = call i32 @snprintf(i8* %23, i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %24, i32 %26, i32 %28)
%30 = load %struct.udev*, %struct.udev** %5
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%32 = call %struct.udev_device* @udev_device_new_from_syspath(%struct.udev* %30, i8* %31)
store %struct.udev_device* %32, %struct.udev_device** %4
br label %33
33: ; preds = %22, %19
%34 = load %struct.udev_device*, %struct.udev_device** %4
ret %struct.udev_device* %34
}

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