#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 /*<<< orphan*/ isdigit(char const);
int /*<<< orphan*/ ispunct(char const);
int /*<<< orphan*/ makedev(unsigned int, unsigned int);
unsigned int strtoul(char const *, char **, int /*<<< orphan*/);
int parse_device(const char *input, dev_t *dev) {
  unsigned int major, minor;
  const char *pos = input;
  if (!isdigit(*pos))
    return 0;
  major = strtoul(pos, (char **)&pos, 0);
  if (!ispunct(*pos))
    return 0;
  ++pos;
  if (!isdigit(*pos))
    return 0;
  minor = strtoul(pos, (char **)&pos, 0);
  if (*pos != '\0')
    return 0;
  *dev = makedev(major, minor);
  return 1;
}


x86 assembly (clang, -O0):
<parse_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1179 <parse_device+0x39>
movl   $0x0,-0x4(%rbp)
jmp    1221 <parse_device+0xe1>
mov    -0x28(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1040 <ispunct@plt>
cmp    $0x0,%eax
jne    11ac <parse_device+0x6c>
movl   $0x0,-0x4(%rbp)
jmp    1221 <parse_device+0xe1>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11d9 <parse_device+0x99>
movl   $0x0,-0x4(%rbp)
jmp    1221 <parse_device+0xe1>
mov    -0x28(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1207 <parse_device+0xc7>
movl   $0x0,-0x4(%rbp)
jmp    1221 <parse_device+0xe1>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1050 <makedev@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_device>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdi,0x8(%rsp)
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11cd <parse_device+0x8d>
lea    0x8(%rsp),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,%r14d
mov    0x8(%rsp),%rbx
movsbl (%rbx),%edi
call   1040 <ispunct@plt>
test   %eax,%eax
je     11cf <parse_device+0x8f>
lea    0x1(%rbx),%r12
mov    %r12,0x8(%rsp)
movsbl 0x1(%rbx),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11cf <parse_device+0x8f>
lea    0x8(%rsp),%rsi
xor    %ebp,%ebp
mov    %r12,%rdi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    11cf <parse_device+0x8f>
mov    %r14d,%edi
mov    %eax,%esi
call   1050 <makedev@plt>
mov    %eax,(%r15)
mov    $0x1,%ebp
jmp    11cf <parse_device+0x8f>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_device(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = load i8*, i8** %4
store i8* %9, i8** %8
%10 = load i8*, i8** %8
%11 = load i8, i8* %10
%12 = call i32 @isdigit(i8 signext %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 0, i32* %3
br label %44
15: ; preds = %2
%16 = load i8*, i8** %8
%17 = call i32 @strtoul(i8* %16, i8** %8, i32 0)
store i32 %17, i32* %6
%18 = load i8*, i8** %8
%19 = load i8, i8* %18
%20 = call i32 @ispunct(i8 signext %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %15
store i32 0, i32* %3
br label %44
23: ; preds = %15
%24 = load i8*, i8** %8
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = load i8, i8* %26
%28 = call i32 @isdigit(i8 signext %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %23
store i32 0, i32* %3
br label %44
31: ; preds = %23
%32 = load i8*, i8** %8
%33 = call i32 @strtoul(i8* %32, i8** %8, i32 0)
store i32 %33, i32* %7
%34 = load i8*, i8** %8
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %31
store i32 0, i32* %3
br label %44
39: ; preds = %31
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = call i32 @makedev(i32 %40, i32 %41)
%43 = load i32*, i32** %5
store i32 %42, i32* %43
store i32 1, i32* %3
br label %44
44: ; preds = %39, %38, %30, %22, %14
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
define i32 @parse_device(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* %0, i8** %3
%5 = load i8, i8* %0
%6 = tail call i32 @isdigit(i8 signext %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %26, label %8
8: ; preds = %2
%9 = call i32 @strtoul(i8* %0, i8** %3, i32 0)
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = tail call i32 @ispunct(i8 signext %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %10, i64 1
store i8* %15, i8** %3
%16 = load i8, i8* %15
%17 = tail call i32 @isdigit(i8 signext %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %14
%20 = call i32 @strtoul(i8* %15, i8** %3, i32 0)
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 @makedev(i32 %9, i32 %20)
store i32 %25, i32* %1
br label %26
26: ; preds = %19, %14, %8, %2, %24
%27 = phi i32 [ 1, %24 ], [ 0, %2 ], [ 0, %8 ], [ 0, %14 ], [ 0, %19 ]
ret i32 %27
}