#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*/ S_ISCHR(int /*<<< orphan*/);
int /*<<< orphan*/ perr(char *, ...);
scalar_t__ stat(char const *, struct stat *);
const char *devcheck(const char *origname) {
  struct stat stslash, stchar;
  if (stat("/", &stslash) < 0) {
    perr("Can't stat `/'");
    return (origname);
  }
  if (stat(origname, &stchar) < 0) {
    perr("Can't stat %s\n", origname);
    return (origname);
  }
  if (!S_ISCHR(stchar.st_mode)) {
    perr("%s is not a char device\n", origname);
  }
  return (origname);
}


x86 assembly (clang, -O0):
<devcheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    1171 <devcheck+0x41>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <perr@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d2 <devcheck+0xa2>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    11a7 <devcheck+0x77>
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <perr@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d2 <devcheck+0xa2>
mov    -0x20(%rbp),%edi
call   1050 <S_ISCHR@plt>
cmp    $0x0,%eax
jne    11ca <devcheck+0x9a>
mov    -0x10(%rbp),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <perr@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devcheck>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xec1(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %rax,%rax
js     1173 <devcheck+0x43>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
test   %rax,%rax
js     1183 <devcheck+0x53>
mov    (%rsp),%edi
call   1050 <S_ISCHR@plt>
test   %eax,%eax
jne    1194 <devcheck+0x64>
lea    0xeaf(%rip),%rdi
jmp    118a <devcheck+0x5a>
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1030 <perr@plt>
jmp    1194 <devcheck+0x64>
lea    0xe87(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <perr@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"/\00"
@.str.1 = [15 x i8] c"Can't stat `/'\00"
@.str.2 = [15 x i8] c"Can't stat %s\0A\00"
@.str.3 = [25 x i8] c"%s is not a char device\0A\00"
define i8* @devcheck(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca %struct.stat
store i8* %0, i8** %3
%6 = call i64 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.stat* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 (i8*, ...) @perr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%10 = load i8*, i8** %3
store i8* %10, i8** %2
br label %29
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i64 @stat(i8* %12, %struct.stat* %5)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @perr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %3
store i8* %18, i8** %2
br label %29
19: ; preds = %11
%20 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @S_ISCHR(i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = call i32 (i8*, ...) @perr(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %19
%28 = load i8*, i8** %3
store i8* %28, i8** %2
br label %29
29: ; preds = %27, %15, %8
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"/\00"
@.str.1 = [15 x i8] c"Can't stat `/'\00"
@.str.2 = [15 x i8] c"Can't stat %s\0A\00"
@.str.3 = [25 x i8] c"%s is not a char device\0A\00"
define i8* @devcheck(i8* returned %0) {
%2 = alloca %struct.stat
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %2 to i8*
%5 = bitcast %struct.stat* %3 to i8*
%6 = call i64 @stat(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 (i8*, ...) @perr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %22
10: ; preds = %1
%11 = call i64 @stat(i8* %0, %struct.stat* %3)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (i8*, ...) @perr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %22
15: ; preds = %10
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @S_ISCHR(i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @perr(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %22
22: ; preds = %15, %20, %13, %8
ret i8* %0
}