#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*/ fprintf(int /*<<< orphan*/, char *);
int lookup_i2c_bus_by_name(char const *);
int /*<<< orphan*/ stderr;
long strtol(char const *, char **, int /*<<< orphan*/);
int lookup_i2c_bus(const char *i2cbus_arg) {
  long i2cbus;
  char *end;
  i2cbus = strtol(i2cbus_arg, &end, 0);
  if (*end || !*i2cbus_arg) {
    return lookup_i2c_bus_by_name(i2cbus_arg);
  }
  if (i2cbus < 0 || i2cbus > 0xff) {
    fprintf(stderr, "Error: I2C bus out of range (0-255)!\n");
    return -2;
  }
  return i2cbus;
}


x86 assembly (clang, -O0):
<lookup_i2c_bus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116c <lookup_i2c_bus+0x3c>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    117d <lookup_i2c_bus+0x4d>
mov    -0x10(%rbp),%rdi
call   1050 <lookup_i2c_bus_by_name@plt>
mov    %eax,-0x4(%rbp)
jmp    11be <lookup_i2c_bus+0x8e>
cmpq   $0x0,-0x18(%rbp)
jl     1196 <lookup_i2c_bus+0x66>
cmpq   $0xff,-0x18(%rbp)
jle    11b7 <lookup_i2c_bus+0x87>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11be <lookup_i2c_bus+0x8e>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup_i2c_bus>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
je     115b <lookup_i2c_bus+0x2b>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1050 <lookup_i2c_bus_by_name@plt>
cmpb   $0x0,(%rbx)
je     114e <lookup_i2c_bus+0x1e>
cmp    $0x100,%rax
jb     1182 <lookup_i2c_bus+0x52>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xfffffffe,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"Error: I2C bus out of range (0-255)!\0A\00"
define i32 @lookup_i2c_bus(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strtol(i8* %6, i8** %5, i32 0)
store i64 %7, i64* %4
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12, %1
%17 = load i8*, i8** %3
%18 = call i32 @lookup_i2c_bus_by_name(i8* %17)
store i32 %18, i32* %2
br label %31
19: ; preds = %12
%20 = load i64, i64* %4
%21 = icmp slt i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i64, i64* %4
%24 = icmp sgt i64 %23, 255
br i1 %24, label %25, label %28
25: ; preds = %22, %19
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 -2, i32* %2
br label %31
28: ; preds = %22
%29 = load i64, i64* %4
%30 = trunc i64 %29 to i32
store i32 %30, i32* %2
br label %31
31: ; preds = %28, %25, %16
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"Error: I2C bus out of range (0-255)!\0A\00"
define i32 @lookup_i2c_bus(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8, %1
%12 = tail call i32 @lookup_i2c_bus_by_name(i8* %0)
br label %20
13: ; preds = %8
%14 = icmp ugt i64 %4, 255
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %20
18: ; preds = %13
%19 = trunc i64 %4 to i32
br label %20
20: ; preds = %18, %15, %11
%21 = phi i32 [ %12, %11 ], [ -2, %15 ], [ %19, %18 ]
ret i32 %21
}