#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_dev;
};

/* Variables and functions */
int major(int /*<<< orphan*/);
int minor(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char const *, struct stat *);
int stat_device(const char *name, int export, const char *prefix) {
  struct stat statbuf;
  if (stat(name, &statbuf) != 0)
    return -1;
  if (export) {
    if (prefix == NULL)
      prefix = "INFO_";
    printf("%sMAJOR=%d\n"
           "%sMINOR=%d\n",
           prefix, major(statbuf.st_dev), prefix, minor(statbuf.st_dev));
  } else
    printf("%d:%d\n", major(statbuf.st_dev), minor(statbuf.st_dev));
  return 0;
}


x86 assembly (clang, -O0):
<stat_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
je     1176 <stat_device+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    1207 <stat_device+0xc7>
cmpl   $0x0,-0x14(%rbp)
je     11da <stat_device+0x9a>
cmpq   $0x0,-0x20(%rbp)
jne    1196 <stat_device+0x56>
lea    0xe6e(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%edi
call   1050 <major@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%edi
call   1030 <minor@plt>
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    %eax,%r8d
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1200 <stat_device+0xc0>
mov    -0x28(%rbp),%edi
call   1050 <major@plt>
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%edi
call   1030 <minor@plt>
mov    -0x44(%rbp),%esi
mov    %eax,%edx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stat_device>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    11ce <stat_device+0x8e>
test   %ebp,%ebp
je     11a6 <stat_device+0x66>
test   %r14,%r14
lea    0xe91(%rip),%rbp
cmovne %r14,%rbp
mov    0x8(%rsp),%edi
call   1050 <major@plt>
mov    %eax,%r14d
mov    0x8(%rsp),%edi
call   1030 <minor@plt>
lea    0xe77(%rip),%rdi
xor    %ebx,%ebx
mov    %rbp,%rsi
mov    %r14d,%edx
mov    %rbp,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ce <stat_device+0x8e>
mov    0x8(%rsp),%edi
call   1050 <major@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%edi
call   1030 <minor@plt>
lea    0xe5c(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [6 x i8] c"INFO_\00"
@.str.1 = [23 x i8] c"%sMAJOR=%d\0A%sMINOR=%d\0A\00"
@.str.2 = [7 x i8] c"%d:%d\0A\00"
define i32 @stat_device(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.stat
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = call i64 @stat(i8* %9, %struct.stat* %8)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %39
13: ; preds = %3
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = load i8*, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %16
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %7
br label %20
20: ; preds = %19, %16
%21 = load i8*, i8** %7
%22 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @major(i32 %23)
%25 = load i8*, i8** %7
%26 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @minor(i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %24, i8* %25, i32 %28)
br label %38
30: ; preds = %13
%31 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @major(i32 %32)
%34 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @minor(i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %36)
br label %38
38: ; preds = %30, %20
store i32 0, i32* %4
br label %39
39: ; preds = %38, %12
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c"INFO_\00"
@.str.1 = [23 x i8] c"%sMAJOR=%d\0A%sMINOR=%d\0A\00"
@.str.2 = [7 x i8] c"%d:%d\0A\00"
define i32 @stat_device(i8* %0, i32 %1, i8* %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = call i64 @stat(i8* %0, %struct.stat* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %26
8: ; preds = %3
%9 = icmp eq i32 %1, 0
br i1 %9, label %19, label %10
10: ; preds = %8
%11 = icmp eq i8* %2, null
%12 = select i1 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %2
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @major(i32 %14)
%16 = load i32, i32* %13
%17 = call i32 @minor(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %15, i8* %12, i32 %17)
br label %26
19: ; preds = %8
%20 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @major(i32 %21)
%23 = load i32, i32* %20
%24 = call i32 @minor(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %24)
br label %26
26: ; preds = %10, %19, %3
%27 = phi i32 [ -1, %3 ], [ 0, %19 ], [ 0, %10 ]
ret i32 %27
}