#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 */
int /*<<< orphan*/ strcmp(char const *, char *);
int strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
int sensors_parse_i2cbus_name(const char *name, int *res) {
  int i;
  if (!strcmp(name, "isa")) {
    *res = -1;
    return 0;
  }
  if (strncmp(name, "i2c-", 4)) {
    *res = -4;
    return 0;
  }
  name += 4;
  if ((strlen(name) > 3) || (strlen(name) == 0))
    return -7;
  *res = 0;
  for (i = 0;; i++) {
    switch (name[i]) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      *res = *res * 10 + name[i] - '0';
      break;
    case 0:
      return 0;
    default:
      return -7;
    }
  }
}


x86 assembly (clang, -O0):
<sensors_parse_i2cbus_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    116f <sensors_parse_i2cbus_name+0x3f>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    126f <sensors_parse_i2cbus_name+0x13f>
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11a4 <sensors_parse_i2cbus_name+0x74>
mov    -0x18(%rbp),%rax
movl   $0xfffffffc,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    126f <sensors_parse_i2cbus_name+0x13f>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x3,%eax
jg     11d4 <sensors_parse_i2cbus_name+0xa4>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    11e0 <sensors_parse_i2cbus_name+0xb0>
movl   $0xfffffff9,-0x4(%rbp)
jmp    126f <sensors_parse_i2cbus_name+0x13f>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
test   %eax,%eax
je     1244 <sensors_parse_i2cbus_name+0x114>
jmp    120d <sensors_parse_i2cbus_name+0xdd>
mov    -0x20(%rbp),%eax
add    $0xffffffd0,%eax
sub    $0x9,%eax
ja     1250 <sensors_parse_i2cbus_name+0x120>
jmp    1221 <sensors_parse_i2cbus_name+0xf1>
mov    -0x18(%rbp),%rax
imul   $0xa,(%rax),%ecx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rdx
movsbl (%rax,%rdx,1),%eax
add    %eax,%ecx
sub    $0x30,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    125c <sensors_parse_i2cbus_name+0x12c>
movl   $0x0,-0x4(%rbp)
jmp    126f <sensors_parse_i2cbus_name+0x13f>
movl   $0xfffffff9,-0x4(%rbp)
jmp    126f <sensors_parse_i2cbus_name+0x13f>
jmp    1261 <sensors_parse_i2cbus_name+0x131>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f1 <sensors_parse_i2cbus_name+0xc1>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sensors_parse_i2cbus_name>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xebf(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     116e <sensors_parse_i2cbus_name+0x3e>
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1179 <sensors_parse_i2cbus_name+0x49>
movl   $0xfffffffc,(%r14)
xor    %ebp,%ebp
jmp    11d3 <sensors_parse_i2cbus_name+0xa3>
movl   $0xffffffff,(%r14)
xor    %ebp,%ebp
jmp    11d3 <sensors_parse_i2cbus_name+0xa3>
add    $0x4,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0xfffffff9,%ebp
cmp    $0x3,%eax
jg     11d3 <sensors_parse_i2cbus_name+0xa3>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11d3 <sensors_parse_i2cbus_name+0xa3>
movl   $0x0,(%r14)
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rbx),%ecx
lea    -0x30(%rcx),%edx
cmp    $0xa,%edx
jae    11cd <sensors_parse_i2cbus_name+0x9d>
lea    (%rax,%rax,4),%eax
lea    (%rcx,%rax,2),%eax
add    $0xffffffd0,%eax
mov    %eax,(%r14)
add    $0x1,%rbx
jmp    11b0 <sensors_parse_i2cbus_name+0x80>
test   %ecx,%ecx
jne    11d3 <sensors_parse_i2cbus_name+0xa3>
mov    %ecx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"isa\00"
@.str.1 = [5 x i8] c"i2c-\00"
define i32 @sensors_parse_i2cbus_name(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%8 = call i32 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = load i32*, i32** %5
store i32 -1, i32* %11
store i32 0, i32* %3
br label %57
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i32*, i32** %5
store i32 -4, i32* %17
store i32 0, i32* %3
br label %57
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 4
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
%23 = icmp sgt i32 %22, 3
br i1 %23, label %28, label %24
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24, %18
store i32 -7, i32* %3
br label %57
29: ; preds = %24
%30 = load i32*, i32** %5
store i32 0, i32* %30
store i32 0, i32* %6
br label %31
31: ; preds = %54, %29
%32 = load i8*, i8** %4
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
switch i32 %37, label %52 [
i32 48, label %38
i32 49, label %38
i32 50, label %38
i32 51, label %38
i32 52, label %38
i32 53, label %38
i32 54, label %38
i32 55, label %38
i32 56, label %38
i32 57, label %38
i32 0, label %51
]
38: ; preds = %31, %31, %31, %31, %31, %31, %31, %31, %31, %31
%39 = load i32*, i32** %5
%40 = load i32, i32* %39
%41 = mul nsw i32 %40, 10
%42 = load i8*, i8** %4
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = add nsw i32 %41, %47
%49 = sub nsw i32 %48, 48
%50 = load i32*, i32** %5
store i32 %49, i32* %50
br label %53
51: ; preds = %31
store i32 0, i32* %3
br label %57
52: ; preds = %31
store i32 -7, i32* %3
br label %57
53: ; preds = %38
br label %54
54: ; preds = %53
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %31
57: ; preds = %52, %51, %28, %16, %10
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [4 x i8] c"isa\00"
@.str.1 = [5 x i8] c"i2c-\00"
define i32 @sensors_parse_i2cbus_name(i8* %0, i32* nocapture %1) {
%3 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %2
store i32 -1, i32* %1
br label %31
6: ; preds = %2
%7 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %6
store i32 -4, i32* %1
br label %31
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %0, i64 4
%12 = tail call i32 @strlen(i8* %11)
%13 = icmp sgt i32 %12, 3
br i1 %13, label %31, label %14
14: ; preds = %10
%15 = tail call i32 @strlen(i8* %11)
%16 = icmp eq i32 %15, 0
br i1 %16, label %31, label %17
17: ; preds = %14
store i32 0, i32* %1
br label %18
18: ; preds = %24, %17
%19 = phi i32 [ %27, %24 ], [ 0, %17 ]
%20 = phi i64 [ %28, %24 ], [ 0, %17 ]
%21 = getelementptr inbounds i8, i8* %11, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
switch i32 %23, label %31 [
i32 48, label %24
i32 49, label %24
i32 50, label %24
i32 51, label %24
i32 52, label %24
i32 53, label %24
i32 54, label %24
i32 55, label %24
i32 56, label %24
i32 57, label %24
i32 0, label %29
]
24: ; preds = %18, %18, %18, %18, %18, %18, %18, %18, %18, %18
%25 = mul nsw i32 %19, 10
%26 = add nsw i32 %23, -48
%27 = add i32 %26, %25
store i32 %27, i32* %1
%28 = add nuw i64 %20, 1
br label %18
29: ; preds = %18
%30 = sext i8 %22 to i32
br label %31
31: ; preds = %18, %29, %10, %14, %9, %5
%32 = phi i32 [ 0, %9 ], [ 0, %5 ], [ -7, %14 ], [ -7, %10 ], [ %30, %29 ], [ -7, %18 ]
ret i32 %32
}