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

/* Variables and functions */
int PATH_MAX;
char *__lookup_dev(char *, int /*<<< orphan*/, int /*<<< orphan*/, int);
char *dm_get_dir();
scalar_t__ dm_is_dm_device(int, int);
int /*<<< orphan*/ makedev(int, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *lookup_dev_old(int major, int minor) {
  dev_t dev;
  char *result = NULL, buf[PATH_MAX + 1];
  dev = makedev(major, minor);
  strncpy(buf, "/dev", PATH_MAX);
  buf[PATH_MAX] = '\0';
  if ((result = __lookup_dev(buf, dev, 0, 0)))
    return result;
  if (dm_is_dm_device(major, minor)) {
    strncpy(buf, dm_get_dir(), PATH_MAX);
    if ((result = __lookup_dev(buf, dev, 0, 0)))
      return result;
  }
  strncpy(buf, "/dev", PATH_MAX);
  return __lookup_dev(buf, dev, 0, 4);
}


x86 assembly (clang, -O0):
<lookup_dev_old>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1070 <makedev@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,-0x14(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
lea    0xe49(%rip),%rsi
call   1040 <strncpy@plt>
mov    -0x40(%rbp),%rdi
mov    0x2e29(%rip),%rax
movslq (%rax),%rax
movb   $0x0,(%rdi,%rax,1)
mov    -0x14(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1060 <__lookup_dev@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11fc <lookup_dev_old+0xac>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    129b <lookup_dev_old+0x14b>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <dm_is_dm_device@plt>
cmp    $0x0,%rax
je     1264 <lookup_dev_old+0x114>
mov    $0x0,%al
call   1050 <dm_get_dir@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rsi
mov    0x2dca(%rip),%rax
mov    (%rax),%edx
call   1040 <strncpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1060 <__lookup_dev@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     125f <lookup_dev_old+0x10f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    129b <lookup_dev_old+0x14b>
jmp    1264 <lookup_dev_old+0x114>
mov    -0x40(%rbp),%rdi
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
lea    0xd88(%rip),%rsi
call   1040 <strncpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1060 <__lookup_dev@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup_dev_old>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r12d
mov    0x2e85(%rip),%r13
mov    0x0(%r13),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
call   1070 <makedev@plt>
mov    %eax,%r14d
mov    0x0(%r13),%edx
lea    0xe6a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strncpy@plt>
movslq 0x0(%r13),%rax
movb   $0x0,(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <__lookup_dev@plt>
test   %rax,%rax
jne    1219 <lookup_dev_old+0xc9>
mov    %r12d,%edi
mov    %r15d,%esi
call   1030 <dm_is_dm_device@plt>
test   %rax,%rax
je     11f4 <lookup_dev_old+0xa4>
xor    %eax,%eax
call   1050 <dm_get_dir@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strncpy@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <__lookup_dev@plt>
test   %rax,%rax
jne    1219 <lookup_dev_old+0xc9>
mov    0x0(%r13),%edx
lea    0xe01(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strncpy@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %edx,%edx
mov    $0x4,%ecx
call   1060 <__lookup_dev@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"/dev\00"
define i8* @lookup_dev_old(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* null, i8** %7
%11 = load i32, i32* @PATH_MAX
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = call i32 @makedev(i32 %16, i32 %17)
store i32 %18, i32* %6
%19 = load i32, i32* @PATH_MAX
%20 = call i32 @strncpy(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @PATH_MAX
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %15, i64 %22
store i8 0, i8* %23
%24 = load i32, i32* %6
%25 = call i8* @__lookup_dev(i8* %15, i32 %24, i32 0, i32 0)
store i8* %25, i8** %7
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %2
%28 = load i8*, i8** %7
store i8* %28, i8** %3
store i32 1, i32* %10
br label %49
29: ; preds = %2
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = call i64 @dm_is_dm_device(i32 %30, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %29
%35 = call i8* (...) @dm_get_dir()
%36 = load i32, i32* @PATH_MAX
%37 = call i32 @strncpy(i8* %15, i8* %35, i32 %36)
%38 = load i32, i32* %6
%39 = call i8* @__lookup_dev(i8* %15, i32 %38, i32 0, i32 0)
store i8* %39, i8** %7
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = load i8*, i8** %7
store i8* %42, i8** %3
store i32 1, i32* %10
br label %49
43: ; preds = %34
br label %44
44: ; preds = %43, %29
%45 = load i32, i32* @PATH_MAX
%46 = call i32 @strncpy(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %6
%48 = call i8* @__lookup_dev(i8* %15, i32 %47, i32 0, i32 4)
store i8* %48, i8** %3
store i32 1, i32* %10
br label %49
49: ; preds = %44, %41, %27
%50 = load i8*, i8** %8
%51 = load i8*, i8** %3
ret i8* %51
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"/dev\00"
define i8* @lookup_dev_old(i32 %0, i32 %1) {
%3 = load i32, i32* @PATH_MAX
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = tail call i32 @makedev(i32 %0, i32 %1)
%8 = load i32, i32* @PATH_MAX
%9 = call i32 @strncpy(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* @PATH_MAX
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %6, i64 %11
store i8 0, i8* %12
%13 = call i8* @__lookup_dev(i8* %6, i32 %7, i32 0, i32 0)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %28
15: ; preds = %2
%16 = call i64 @dm_is_dm_device(i32 %0, i32 %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = call i8* (...) @dm_get_dir()
%20 = load i32, i32* @PATH_MAX
%21 = call i32 @strncpy(i8* %6, i8* %19, i32 %20)
%22 = call i8* @__lookup_dev(i8* %6, i32 %7, i32 0, i32 0)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %28
24: ; preds = %18, %15
%25 = load i32, i32* @PATH_MAX
%26 = call i32 @strncpy(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = call i8* @__lookup_dev(i8* %6, i32 %7, i32 0, i32 4)
br label %28
28: ; preds = %18, %2, %24
%29 = phi i8* [ %27, %24 ], [ %13, %2 ], [ %22, %18 ]
ret i8* %29
}