#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*/);
int major(int /*<<< orphan*/);
scalar_t__ stat(char const *, struct stat *);
int crypt_loop_device(const char *loop) {
  struct stat st;
  if (!loop)
    return 0;
  if (stat(loop, &st) || !S_ISBLK(st.st_mode) || major(st.st_rdev) != 7)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<crypt_loop_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <crypt_loop_device+0x23>
movl   $0x0,-0x4(%rbp)
jmp    119f <crypt_loop_device+0x6f>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jne    118c <crypt_loop_device+0x5c>
mov    -0x14(%rbp),%edi
call   1050 <S_ISBLK@plt>
cmp    $0x0,%eax
je     118c <crypt_loop_device+0x5c>
mov    -0x18(%rbp),%edi
call   1030 <major@plt>
cmp    $0x7,%eax
je     1198 <crypt_loop_device+0x68>
movl   $0x0,-0x4(%rbp)
jmp    119f <crypt_loop_device+0x6f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypt_loop_device>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
test   %rdi,%rdi
je     1169 <crypt_loop_device+0x39>
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %rax,%rax
jne    1169 <crypt_loop_device+0x39>
mov    0xc(%rsp),%edi
call   1050 <S_ISBLK@plt>
test   %eax,%eax
je     1169 <crypt_loop_device+0x39>
mov    0x8(%rsp),%edi
call   1030 <major@plt>
xor    %ebx,%ebx
cmp    $0x7,%eax
sete   %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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