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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ makedev(int, int);
int /*<<< orphan*/ printf(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
int dinfo_extract_dev(dev_t *dev, char *str, int readbuflen) {
  char tmp[readbuflen];
  char *p = NULL;
  int ma, mi;
  bzero(tmp, readbuflen);
  strncpy(tmp, str, readbuflen);
  if ((p = strchr(tmp, ':')) == NULL) {
    printf("Error: unable to extract major/minor\n");
    return -1;
  }
  *p = '\0';
  ma = atoi(tmp);
  mi = atoi(p + sizeof(char));
  *dev = makedev(ma, mi);
  return 0;
}


x86 assembly (clang, -O0):
<dinfo_extract_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x1c(%rbp),%esi
call   1060 <bzero@plt>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x50(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11f4 <dinfo_extract_dev+0x94>
lea    0xe24(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1238 <dinfo_extract_dev+0xd8>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
call   1080 <atoi@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1080 <atoi@plt>
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x40(%rbp),%esi
call   1070 <makedev@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dinfo_extract_dev>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r14
mov    %edx,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %edx,%esi
call   1060 <bzero@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11dd <dinfo_extract_dev+0x7d>
mov    %rax,%r15
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
add    $0x1,%r15
mov    %r15,%rdi
call   1080 <atoi@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <makedev@plt>
mov    %eax,(%r14)
xor    %eax,%eax
jmp    11ee <dinfo_extract_dev+0x8e>
lea    0xe1c(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Error: unable to extract major/minor\0A\00"
define i32 @dinfo_extract_dev(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%14 = load i32, i32* %7
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %8
%17 = alloca i8, i64 %15
store i64 %15, i64* %9
store i8* null, i8** %10
%18 = load i32, i32* %7
%19 = call i32 @bzero(i8* %17, i32 %18)
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = call i32 @strncpy(i8* %17, i8* %20, i32 %21)
%23 = call i8* @strchr(i8* %17, i8 signext 58)
store i8* %23, i8** %10
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %3
%26 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %13
br label %37
27: ; preds = %3
%28 = load i8*, i8** %10
store i8 0, i8* %28
%29 = call i32 @atoi(i8* %17)
store i32 %29, i32* %11
%30 = load i8*, i8** %10
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %12
%33 = load i32, i32* %11
%34 = load i32, i32* %12
%35 = call i32 @makedev(i32 %33, i32 %34)
%36 = load i32*, i32** %5
store i32 %35, i32* %36
store i32 0, i32* %4
store i32 1, i32* %13
br label %37
37: ; preds = %27, %25
%38 = load i8*, i8** %8
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@str = [37 x i8] c"Error: unable to extract major/minor\00"
define i32 @dinfo_extract_dev(i32* nocapture writeonly %0, i8* %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @bzero(i8* %5, i32 %2)
%7 = call i32 @strncpy(i8* %5, i8* %1, i32 %2)
%8 = call i8* @strchr(i8* %5, i8 signext 58)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
br label %17
12: ; preds = %3
store i8 0, i8* %8
%13 = call i32 @atoi(i8* %5)
%14 = getelementptr inbounds i8, i8* %8, i64 1
%15 = call i32 @atoi(i8* %14)
%16 = call i32 @makedev(i32 %13, i32 %15)
store i32 %16, i32* %0
br label %17
17: ; preds = %12, %10
%18 = phi i32 [ -1, %10 ], [ 0, %12 ]
ret i32 %18
}