#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ S_ISBLK(int /*<<< orphan*/);
int /*<<< orphan*/ add_to_bdevlist(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int lstat(char *, struct stat *);
int /*<<< orphan*/ printf(char *, char *);
void stat_dev(char *name) {
  struct stat sb;
  int ret;
  ret = lstat(name, &sb);
  if (ret == -1) {
    printf("Couldn't open %s\n", name);
    exit(EXIT_FAILURE);
  }
  if (!(S_ISBLK(sb.st_mode))) {
    printf("Sorry, %s doesn't look like a block device.\n", name);
    exit(EXIT_FAILURE);
  }
  add_to_bdevlist(name);
}


x86 assembly (clang, -O0):
<stat_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <lstat@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1194 <stat_dev+0x44>
mov    -0x8(%rbp),%rsi
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%edi
call   1060 <S_ISBLK@plt>
cmp    $0x0,%eax
jne    11c3 <stat_dev+0x73>
mov    -0x8(%rbp),%rsi
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <add_to_bdevlist@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stat_dev>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <lstat@plt>
cmp    $0xffffffff,%eax
je     1181 <stat_dev+0x31>
mov    0x8(%rsp),%edi
call   1060 <S_ISBLK@plt>
test   %eax,%eax
je     118a <stat_dev+0x3a>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1050 <add_to_bdevlist@plt>
lea    0xe78(%rip),%rdi
jmp    1191 <stat_dev+0x41>
lea    0xe81(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [18 x i8] c"Couldn't open %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [45 x i8] c"Sorry, %s doesn't look like a block device.\0A\00"
define void @stat_dev(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @lstat(i8* %5, %struct.stat* %3)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @S_ISBLK(i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = load i8*, i8** %2
%21 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %14
%25 = load i8*, i8** %2
%26 = call i32 @add_to_bdevlist(i8* %25)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [18 x i8] c"Couldn't open %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [45 x i8] c"Sorry, %s doesn't look like a block device.\0A\00"
define void @stat_dev(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @lstat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @S_ISBLK(i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = tail call i32 @add_to_bdevlist(i8* %0)
ret void
}