#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 */
typedef int /*<<< orphan*/ dev_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int /*<<< orphan*/ makedev(int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
dev_t devid_from_file(char *filename) {
  FILE *fhan;
  int major, minor;
  dev_t devid = 0;
  fhan = fopen(filename, "r");
  if (!fhan) {
    fprintf(stderr, "fopen: %s", strerror(errno));
    goto out;
  }
  if (fscanf(fhan, "%d:%d", &major, &minor) == 2)
    devid = makedev(major, minor);
out:
  if (fhan)
    fclose(fhan);
  return devid;
}


x86 assembly (clang, -O0):
<devid_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c3 <devid_from_file+0x63>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11f7 <devid_from_file+0x97>
mov    -0x10(%rbp),%rdi
lea    0xe3e(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1040 <fscanf@plt>
cmp    $0x2,%eax
jne    11f2 <devid_from_file+0x92>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1070 <makedev@plt>
mov    %eax,-0x1c(%rbp)
jmp    11f7 <devid_from_file+0x97>
cmpq   $0x0,-0x10(%rbp)
je     120b <devid_from_file+0xab>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devid_from_file>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ad <devid_from_file+0x4d>
mov    %rax,%rbx
lea    0xe8e(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
mov    %rax,%rdi
call   1040 <fscanf@plt>
xor    %ebp,%ebp
cmp    $0x2,%eax
jne    11a3 <devid_from_file+0x43>
mov    0x4(%rsp),%edi
mov    (%rsp),%esi
call   1070 <makedev@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11d7 <devid_from_file+0x77>
mov    0x2e2c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe37(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [10 x i8] c"fopen: %s\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"%d:%d\00"
define i32 @devid_from_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %6
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %25
16: ; preds = %1
%17 = load i32*, i32** %3
%18 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5)
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = call i32 @makedev(i32 %21, i32 %22)
store i32 %23, i32* %6
br label %24
24: ; preds = %20, %16
br label %25
25: ; preds = %24, %11
%26 = load i32*, i32** %3
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32*, i32** %3
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %28, %25
%32 = load i32, i32* %6
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [10 x i8] c"fopen: %s\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"%d:%d\00"
define i32 @devid_from_file(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %15, label %8
8: ; preds = %1
%9 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %2, i32* %3)
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = call i32 @makedev(i32 %12, i32 %13)
br label %20
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %23
20: ; preds = %8, %11
%21 = phi i32 [ 0, %8 ], [ %14, %11 ]
%22 = call i32 @fclose(i32* %6)
br label %23
23: ; preds = %15, %20
%24 = phi i32 [ %21, %20 ], [ 0, %15 ]
ret i32 %24
}