#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 scalar_t__ dev_t;

/* Variables and functions */
scalar_t__ NODEV;
int /*<<< orphan*/ S_IFCHR;
char *devname(scalar_t__, int /*<<< orphan*/);
const char *getdev(dev_t dev) {
  static dev_t lastdev = (dev_t)-1;
  static const char *lastname;
  if (dev == NODEV)
    return ("__");
  if (dev == lastdev)
    return (lastname);
  lastdev = dev;
  lastname = devname(dev, S_IFCHR);
  return (lastname);
}


x86 assembly (clang, -O0):
<getdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ec9(%rip),%rcx
cmp    (%rcx),%rax
jne    1140 <getdev+0x30>
lea    0xec9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1190 <getdev+0x80>
mov    -0x10(%rbp),%rax
cmp    0x2edd(%rip),%rax
jne    1161 <getdev+0x51>
mov    0x2ee0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1190 <getdev+0x80>
mov    -0x10(%rbp),%rax
mov    %rax,0x2ebc(%rip)
mov    -0x10(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
call   1030 <devname@plt>
mov    %rax,0x2eb3(%rip)
mov    0x2eac(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdev>:
push   %rax
mov    0x2ed8(%rip),%rax
cmp    %rdi,(%rax)
jne    1126 <getdev+0x16>
lea    0xedc(%rip),%rax
pop    %rcx
ret
cmp    %rdi,0x2efb(%rip)
jne    1138 <getdev+0x28>
mov    0x2f02(%rip),%rax
pop    %rcx
ret
mov    %rdi,0x2ee9(%rip)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
call   1030 <devname@plt>
mov    %rax,0x2ee4(%rip)
pop    %rcx
ret

LLVM IR (-O0):
@getdev.lastdev = internal global i64 -1
@getdev.lastname = internal global i8* null
@NODEV = global i64 0
@.str = [3 x i8] c"__\00"
@S_IFCHR = global i32 0
define i8* @getdev(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = load i64, i64* @NODEV
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
br label %20
8: ; preds = %1
%9 = load i64, i64* %3
%10 = load i64, i64* @getdev.lastdev
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = load i8*, i8** @getdev.lastname
store i8* %13, i8** %2
br label %20
14: ; preds = %8
%15 = load i64, i64* %3
store i64 %15, i64* @getdev.lastdev
%16 = load i64, i64* %3
%17 = load i32, i32* @S_IFCHR
%18 = call i8* @devname(i64 %16, i32 %17)
store i8* %18, i8** @getdev.lastname
%19 = load i8*, i8** @getdev.lastname
store i8* %19, i8** %2
br label %20
20: ; preds = %14, %12, %7
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@getdev.lastdev = internal unnamed_addr global i64 -1
@getdev.lastname = internal unnamed_addr global i8* null
@NODEV = global i64 0
@.str = [3 x i8] c"__\00"
@S_IFCHR = global i32 0
define i8* @getdev(i64 %0) {
%2 = load i64, i64* @NODEV
%3 = icmp eq i64 %2, %0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = load i64, i64* @getdev.lastdev
%6 = icmp eq i64 %5, %0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = load i8*, i8** @getdev.lastname
br label %12
9: ; preds = %4
store i64 %0, i64* @getdev.lastdev
%10 = load i32, i32* @S_IFCHR
%11 = tail call i8* @devname(i64 %0, i32 %10)
store i8* %11, i8** @getdev.lastname
br label %12
12: ; preds = %1, %9, %7
%13 = phi i8* [ %8, %7 ], [ %11, %9 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %13
}