#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;
};

/* Variables and functions */
int path_prepend(char **, char *, unsigned long, ...);
unsigned long strtoul(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ udev_device_get_sysnum(struct udev_device *);
int format_lun_number(struct udev_device *dev, char **path) {
  unsigned long lun = strtoul(udev_device_get_sysnum(dev), NULL, 10);
  if (lun < 256)
    return path_prepend(path, "lun-%d", lun);
  return path_prepend(path, "lun-0x%04x%04x00000000", (lun & 0xffff),
                      (lun >> 16) & 0xffff);
}


x86 assembly (clang, -O0):
<format_lun_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <udev_device_get_sysnum@plt>
mov    %eax,%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x100,-0x20(%rbp)
jae    1189 <format_lun_number+0x59>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1030 <path_prepend@plt>
mov    %eax,-0x4(%rbp)
jmp    11b8 <format_lun_number+0x88>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
and    $0xffff,%rdx
mov    -0x20(%rbp),%rcx
shr    $0x10,%rcx
and    $0xffff,%rcx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1030 <path_prepend@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_lun_number>:
push   %rbx
mov    %rsi,%rbx
call   1040 <udev_device_get_sysnum@plt>
mov    %eax,%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
cmp    $0xff,%rax
ja     1164 <format_lun_number+0x34>
lea    0xeaa(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
xor    %eax,%eax
pop    %rbx
jmp    1030 <path_prepend@plt>
movzwl %ax,%edx
shr    $0x10,%eax
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rcx
xor    %eax,%eax
pop    %rbx
jmp    1030 <path_prepend@plt>

LLVM IR (-O0):
%struct.udev_device = type { i32 }
@.str = [7 x i8] c"lun-%d\00"
@.str.1 = [23 x i8] c"lun-0x%04x%04x00000000\00"
define i32 @format_lun_number(%struct.udev_device* %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.udev_device*
%5 = alloca i8**
%6 = alloca i64
store %struct.udev_device* %0, %struct.udev_device** %4
store i8** %1, i8*** %5
%7 = load %struct.udev_device*, %struct.udev_device** %4
%8 = call i32 @udev_device_get_sysnum(%struct.udev_device* %7)
%9 = call i64 @strtoul(i32 %8, i32* null, i32 10)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = icmp ult i64 %10, 256
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = load i64, i64* %6
%15 = call i32 (i8**, i8*, i64, ...) @path_prepend(i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %14)
store i32 %15, i32* %3
br label %24
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = load i64, i64* %6
%19 = and i64 %18, 65535
%20 = load i64, i64* %6
%21 = lshr i64 %20, 16
%22 = and i64 %21, 65535
%23 = call i32 (i8**, i8*, i64, ...) @path_prepend(i8** %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %19, i64 %22)
store i32 %23, i32* %3
br label %24
24: ; preds = %16, %12
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.udev_device = type { i32 }
@.str = [7 x i8] c"lun-%d\00"
@.str.1 = [23 x i8] c"lun-0x%04x%04x00000000\00"
define i32 @format_lun_number(%struct.udev_device* %0, i8** %1) {
%3 = tail call i32 @udev_device_get_sysnum(%struct.udev_device* %0)
%4 = tail call i64 @strtoul(i32 %3, i32* null, i32 10)
%5 = icmp ult i64 %4, 256
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8**, i8*, i64, ...) @path_prepend(i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %4)
br label %13
8: ; preds = %2
%9 = and i64 %4, 65535
%10 = lshr i64 %4, 16
%11 = and i64 %10, 65535
%12 = tail call i32 (i8**, i8*, i64, ...) @path_prepend(i8** %1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i64 %9, i64 %11)
br label %13
13: ; preds = %8, %6
%14 = phi i32 [ %7, %6 ], [ %12, %8 ]
ret i32 %14
}