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


x86 assembly (clang, -O0):
<is_loop_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    1166 <is_loop_device+0x36>
xor    %eax,%eax
mov    0x2e7c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11a3 <is_loop_device+0x73>
mov    -0x14(%rbp),%edi
call   1050 <S_ISBLK@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     1198 <is_loop_device+0x68>
mov    -0x18(%rbp),%edi
call   1030 <MAJOR@plt>
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_loop_device>:
push   %rax
mov    %rsp,%rsi
call   1040 <stat@plt>
test   %rax,%rax
js     1168 <is_loop_device+0x38>
mov    0x4(%rsp),%edi
call   1050 <S_ISBLK@plt>
test   %rax,%rax
je     1175 <is_loop_device+0x45>
mov    (%rsp),%edi
call   1030 <MAJOR@plt>
mov    %rax,%rcx
mov    0x2e8a(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
sete   %al
pop    %rcx
ret
mov    0x2e69(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@errno = global i32 0
@LOOP_MAJOR = global i64 0
define i32 @is_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 = call i64 @stat(i8* %5, %struct.stat* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = sub nsw i32 0, %9
store i32 %10, i32* %2
br label %25
11: ; preds = %1
%12 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%13 = load i32, i32* %12
%14 = call i64 @S_ISBLK(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @MAJOR(i32 %18)
%20 = load i64, i64* @LOOP_MAJOR
%21 = icmp eq i64 %19, %20
br label %22
22: ; preds = %16, %11
%23 = phi i1 [ false, %11 ], [ %21, %16 ]
%24 = zext i1 %23 to i32
store i32 %24, i32* %2
br label %25
25: ; preds = %22, %8
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@errno = global i32 0
@LOOP_MAJOR = global i64 0
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 slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @errno
%8 = sub nsw i32 0, %7
br label %21
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%11 = load i32, i32* %10
%12 = call i64 @S_ISBLK(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %9
%15 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @MAJOR(i32 %16)
%18 = load i64, i64* @LOOP_MAJOR
%19 = icmp eq i64 %17, %18
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %9, %14, %6
%22 = phi i32 [ %8, %6 ], [ 0, %9 ], [ %20, %14 ]
ret i32 %22
}