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

/* Variables and functions */
scalar_t__ S_ISBLK(int /*<<< orphan*/);
scalar_t__ S_ISLNK(int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
int dev_is_block(struct stat *sb, char *path) {
  if (S_ISBLK(sb->st_mode))
    return 1;
  if (S_ISLNK(sb->st_mode))
    if (!stat(path, sb))
      if (S_ISBLK(sb->st_mode))
        return 1;
  return 0;
}


x86 assembly (clang, -O0):
<dev_is_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISBLK@plt>
cmp    $0x0,%rax
je     1161 <dev_is_block+0x31>
movl   $0x1,-0x4(%rbp)
jmp    11be <dev_is_block+0x8e>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     11b7 <dev_is_block+0x87>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%eax
jne    11b2 <dev_is_block+0x82>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISBLK@plt>
cmp    $0x0,%rax
je     11ad <dev_is_block+0x7d>
movl   $0x1,-0x4(%rbp)
jmp    11be <dev_is_block+0x8e>
jmp    11b2 <dev_is_block+0x82>
jmp    11b7 <dev_is_block+0x87>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dev_is_block>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%edi
call   1050 <S_ISBLK@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1168 <dev_is_block+0x38>
mov    (%rbx),%edi
call   1030 <S_ISLNK@plt>
test   %rax,%rax
je     1166 <dev_is_block+0x36>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <stat@plt>
test   %eax,%eax
je     116f <dev_is_block+0x3f>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%edi
call   1050 <S_ISBLK@plt>
test   %rax,%rax
jne    1168 <dev_is_block+0x38>
jmp    1166 <dev_is_block+0x36>

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @dev_is_block(%struct.stat* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.stat*
%5 = alloca i8*
store %struct.stat* %0, %struct.stat** %4
store i8* %1, i8** %5
%6 = load %struct.stat*, %struct.stat** %4
%7 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = call i64 @S_ISBLK(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %33
12: ; preds = %2
%13 = load %struct.stat*, %struct.stat** %4
%14 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i64 @S_ISLNK(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %32
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = load %struct.stat*, %struct.stat** %4
%21 = call i32 @stat(i8* %19, %struct.stat* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %18
%24 = load %struct.stat*, %struct.stat** %4
%25 = getelementptr inbounds %struct.stat, %struct.stat* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i64 @S_ISBLK(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 1, i32* %3
br label %33
30: ; preds = %23
br label %31
31: ; preds = %30, %18
br label %32
32: ; preds = %31, %12
store i32 0, i32* %3
br label %33
33: ; preds = %32, %29, %11
%34 = load i32, i32* %3
ret i32 %34
}

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