#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 */
scalar_t__ S_ISBLK(int /*<<< orphan*/);
int major(int /*<<< orphan*/);
scalar_t__ stat(char const *, struct stat *);
int is_loop_device(const char *device) {
  struct stat statbuf;
  return (stat(device, &statbuf) == 0 && S_ISBLK(statbuf.st_mode) &&
          major(statbuf.st_rdev) == 7);
}


x86 assembly (clang, -O0):
<is_loop_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
jne    1186 <is_loop_device+0x56>
mov    -0xc(%rbp),%edi
call   1050 <S_ISBLK@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     1186 <is_loop_device+0x56>
mov    -0x10(%rbp),%edi
call   1030 <major@plt>
cmp    $0x7,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_loop_device>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1165 <is_loop_device+0x35>
mov    0xc(%rsp),%edi
call   1050 <S_ISBLK@plt>
test   %rax,%rax
je     1165 <is_loop_device+0x35>
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 @is_loop_device(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @stat(i8* %4, %struct.stat* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%9 = load i32, i32* %8
%10 = call i64 @S_ISBLK(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @major(i32 %14)
%16 = icmp eq i32 %15, 7
br label %17
17: ; preds = %12, %7, %1
%18 = phi i1 [ false, %7 ], [ false, %1 ], [ %16, %12 ]
%19 = zext i1 %18 to i32
ret i32 %19
}

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