#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 stat {
  int /*<<< orphan*/ st_rdev;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ S_ISBLK(int /*<<< orphan*/);
char *devt_to_devpath(int /*<<< orphan*/);
scalar_t__ fstat(int, struct stat *);
char *diskfd_to_devpath(int fd) {
  struct stat st;
  if (fstat(fd, &st) != 0)
    return NULL;
  if (!S_ISBLK(st.st_mode))
    return NULL;
  return devt_to_devpath(st.st_rdev);
}


x86 assembly (clang, -O0):
<diskfd_to_devpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <fstat@plt>
cmp    $0x0,%rax
je     115e <diskfd_to_devpath+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    1188 <diskfd_to_devpath+0x58>
mov    -0x14(%rbp),%edi
call   1040 <S_ISBLK@plt>
cmp    $0x0,%eax
jne    117c <diskfd_to_devpath+0x4c>
movq   $0x0,-0x8(%rbp)
jmp    1188 <diskfd_to_devpath+0x58>
mov    -0x18(%rbp),%edi
call   1030 <devt_to_devpath@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diskfd_to_devpath>:
push   %rax
mov    %rsp,%rsi
call   1050 <fstat@plt>
test   %rax,%rax
je     1142 <diskfd_to_devpath+0x12>
xor    %eax,%eax
pop    %rcx
ret
mov    0x4(%rsp),%edi
call   1040 <S_ISBLK@plt>
test   %eax,%eax
je     113e <diskfd_to_devpath+0xe>
mov    (%rsp),%edi
pop    %rax
jmp    1030 <devt_to_devpath@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
define i8* @diskfd_to_devpath(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.stat
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i64 @fstat(i32 %5, %struct.stat* %4)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* null, i8** %2
br label %19
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%11 = load i32, i32* %10
%12 = call i32 @S_ISBLK(i32 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %9
store i8* null, i8** %2
br label %19
15: ; preds = %9
%16 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i8* @devt_to_devpath(i32 %17)
store i8* %18, i8** %2
br label %19
19: ; preds = %15, %14, %8
%20 = load i8*, i8** %2
ret i8* %20
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
define i8* @diskfd_to_devpath(i32 %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @fstat(i32 %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%8 = load i32, i32* %7
%9 = tail call i32 @S_ISBLK(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i8* @devt_to_devpath(i32 %13)
br label %15
15: ; preds = %6, %1, %11
%16 = phi i8* [ %14, %11 ], [ null, %1 ], [ null, %6 ]
ret i8* %16
}