#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 */
scalar_t__ S_ISBLK(int /*<<< orphan*/);
scalar_t__ S_ISCHR(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
scalar_t__ stat(char *, struct stat *);
char *dev_probe(const char *name) {
  char fn[512];
  struct stat statb;
  sprintf(fn, "/dev/%s", name);
  if (stat(fn, &statb) == 0) {
    if (S_ISBLK(statb.st_mode))
      return "b";
    if (S_ISCHR(statb.st_mode))
      return "c";
  }
  return "f";
}


x86 assembly (clang, -O0):
<dev_probe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe9f(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x210(%rbp),%rdi
lea    -0x218(%rbp),%rsi
call   1030 <stat@plt>
cmp    $0x0,%rax
jne    11d2 <dev_probe+0x92>
mov    -0x218(%rbp),%edi
call   1050 <S_ISBLK@plt>
cmp    $0x0,%rax
je     11a8 <dev_probe+0x68>
lea    0xe69(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11dd <dev_probe+0x9d>
mov    -0x218(%rbp),%edi
call   1040 <S_ISCHR@plt>
cmp    $0x0,%rax
je     11cd <dev_probe+0x8d>
lea    0xe46(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11dd <dev_probe+0x9d>
jmp    11d2 <dev_probe+0x92>
lea    0xe33(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dev_probe>:
push   %rbx
sub    $0x210,%rsp
mov    %rdi,%rdx
lea    0xeae(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <stat@plt>
test   %rax,%rax
je     117a <dev_probe+0x3a>
lea    0xe94(%rip),%rax
jmp    11a6 <dev_probe+0x66>
mov    0x8(%rsp),%edi
call   1050 <S_ISBLK@plt>
test   %rax,%rax
je     1191 <dev_probe+0x51>
lea    0xe79(%rip),%rax
jmp    11a6 <dev_probe+0x66>
mov    0x8(%rsp),%edi
call   1040 <S_ISCHR@plt>
test   %rax,%rax
je     1171 <dev_probe+0x31>
lea    0xe64(%rip),%rax
add    $0x210,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [8 x i8] c"/dev/%s\00"
@.str.1 = [2 x i8] c"b\00"
@.str.2 = [2 x i8] c"c\00"
@.str.3 = [2 x i8] c"f\00"
define i8* @dev_probe(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [512 x i8]
%5 = alloca %struct.stat
store i8* %0, i8** %3
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%10 = call i64 @stat(i8* %9, %struct.stat* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @S_ISBLK(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %26
18: ; preds = %12
%19 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i64 @S_ISCHR(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %26
24: ; preds = %18
br label %25
25: ; preds = %24, %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %26
26: ; preds = %25, %23, %17
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [8 x i8] c"/dev/%s\00"
@.str.1 = [2 x i8] c"b\00"
@.str.2 = [2 x i8] c"c\00"
@.str.3 = [2 x i8] c"f\00"
define i8* @dev_probe(i8* %0) {
%2 = alloca [512 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = bitcast %struct.stat* %3 to i8*
%6 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i64 @stat(i8* %4, %struct.stat* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = call i64 @S_ISBLK(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i32, i32* %10
%16 = call i64 @S_ISCHR(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14, %1
br label %19
19: ; preds = %14, %9, %18
%20 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %18 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %9 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %14 ]
ret i8* %20
}