#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*/ dev_t;

/* Variables and functions */
int major(int /*<<< orphan*/);
int /*<<< orphan*/ makedev(int, int);
int minor(int /*<<< orphan*/);
int /*<<< orphan*/ print_device(struct udev_device *);
int /*<<< orphan*/ printf(char *, int, int);
struct udev_device *udev_device_new_from_devnum(struct udev *, char,
                                                int /*<<< orphan*/);
int /*<<< orphan*/ udev_device_unref(struct udev_device *);
int test_device_devnum(struct udev *udev) {
  dev_t devnum = makedev(1, 3);
  struct udev_device *device;
  printf("looking up device: %u:%u\n", major(devnum), minor(devnum));
  device = udev_device_new_from_devnum(udev, 'c', devnum);
  if (device == NULL)
    return -1;
  print_device(device);
  udev_device_unref(device);
  return 0;
}


x86 assembly (clang, -O0):
<test_device_devnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x1,%edi
mov    $0x3,%esi
call   1070 <makedev@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <major@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <minor@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x63,%esi
call   1080 <udev_device_new_from_devnum@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11de <test_device_devnum+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <test_device_devnum+0x87>
mov    -0x20(%rbp),%rdi
call   1090 <print_device@plt>
mov    -0x20(%rbp),%rdi
call   1060 <udev_device_unref@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_device_devnum>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x1,%edi
mov    $0x3,%esi
call   1070 <makedev@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <major@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <minor@plt>
lea    0xe61(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x63,%esi
mov    %ebp,%edx
call   1080 <udev_device_new_from_devnum@plt>
test   %rax,%rax
je     11d3 <test_device_devnum+0x63>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <print_device@plt>
mov    %rbx,%rdi
call   1060 <udev_device_unref@plt>
xor    %eax,%eax
jmp    11d8 <test_device_devnum+0x68>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev = type { i32 }
%struct.udev_device = type { i32 }
@.str = [26 x i8] c"looking up device: %u:%u\0A\00"
define i32 @test_device_devnum(%struct.udev* %0) {
%2 = alloca i32
%3 = alloca %struct.udev*
%4 = alloca i32
%5 = alloca %struct.udev_device*
store %struct.udev* %0, %struct.udev** %3
%6 = call i32 @makedev(i32 1, i32 3)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = call i32 @major(i32 %7)
%9 = load i32, i32* %4
%10 = call i32 @minor(i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10)
%12 = load %struct.udev*, %struct.udev** %3
%13 = load i32, i32* %4
%14 = call %struct.udev_device* @udev_device_new_from_devnum(%struct.udev* %12, i8 signext 99, i32 %13)
store %struct.udev_device* %14, %struct.udev_device** %5
%15 = load %struct.udev_device*, %struct.udev_device** %5
%16 = icmp eq %struct.udev_device* %15, null
br i1 %16, label %17, label %18
17: ; preds = %1
store i32 -1, i32* %2
br label %23
18: ; preds = %1
%19 = load %struct.udev_device*, %struct.udev_device** %5
%20 = call i32 @print_device(%struct.udev_device* %19)
%21 = load %struct.udev_device*, %struct.udev_device** %5
%22 = call i32 @udev_device_unref(%struct.udev_device* %21)
store i32 0, i32* %2
br label %23
23: ; preds = %18, %17
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.udev = type { i32 }
%struct.udev_device = type { i32 }
@.str = [26 x i8] c"looking up device: %u:%u\0A\00"
define i32 @test_device_devnum(%struct.udev* %0) {
%2 = tail call i32 @makedev(i32 1, i32 3)
%3 = tail call i32 @major(i32 %2)
%4 = tail call i32 @minor(i32 %2)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
%6 = tail call %struct.udev_device* @udev_device_new_from_devnum(%struct.udev* %0, i8 signext 99, i32 %2)
%7 = icmp eq %struct.udev_device* %6, null
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = tail call i32 @print_device(%struct.udev_device* %6)
%10 = tail call i32 @udev_device_unref(%struct.udev_device* %6)
br label %11
11: ; preds = %1, %8
%12 = phi i32 [ 0, %8 ], [ -1, %1 ]
ret i32 %12
}