#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 */

/* Variables and functions */
scalar_t__ strncmp(char *, char *, int);
int strtoul(char *, char **, int);
int devname2devnum(char *name) {
  char *ep;
  int num;
  if (strncmp(name, "md_d", 4) == 0)
    num = -1 - strtoul(name + 4, &ep, 10);
  else
    num = strtoul(name + 2, &ep, 10);
  return num;
}


x86 assembly (clang, -O0):
<devname2devnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec9(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1172 <devname2devnum+0x52>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <devname2devnum+0x6b>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devname2devnum>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xed1(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1156 <devname2devnum+0x36>
add    $0x2,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoul@plt>
jmp    116e <devname2devnum+0x4e>
add    $0x4,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoul@plt>
not    %eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"md_d\00"
define i32 @devname2devnum(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 4
%11 = call i32 @strtoul(i8* %10, i8** %3, i32 10)
%12 = sub nsw i32 -1, %11
store i32 %12, i32* %4
br label %17
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 2
%16 = call i32 @strtoul(i8* %15, i8** %3, i32 10)
store i32 %16, i32* %4
br label %17
17: ; preds = %13, %8
%18 = load i32, i32* %4
ret i32 %18
}

LLVM IR (-O2):
@.str = [5 x i8] c"md_d\00"
define i32 @devname2devnum(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 4
%8 = call i32 @strtoul(i8* %7, i8** %2, i32 10)
%9 = xor i32 %8, -1
br label %13
10: ; preds = %1
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = call i32 @strtoul(i8* %11, i8** %2, i32 10)
br label %13
13: ; preds = %10, %6
%14 = phi i32 [ %9, %6 ], [ %12, %10 ]
ret i32 %14
}