#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;
unsigned long strtoul(char const *, char **, int /*<<< orphan*/);
int lookup_i2c_bus(const char *i2cbus_arg) {
  unsigned long i2cbus;
  char *end;
  i2cbus = strtoul(i2cbus_arg, &end, 0);
  if (*end || !*i2cbus_arg) {
    return lookup_i2c_bus_by_name(i2cbus_arg);
  }
  if (i2cbus > 0xFFFFF) {
    fprintf(stderr, "Error: I2C bus out of range!\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 <strtoul@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    11b3 <lookup_i2c_bus+0x83>
cmpq   $0xfffff,-0x18(%rbp)
jbe    11ac <lookup_i2c_bus+0x7c>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11b3 <lookup_i2c_bus+0x83>
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 <strtoul@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    $0x100000,%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 = [30 x i8] c"Error: I2C bus out of range!\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 @strtoul(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 %28
19: ; preds = %12
%20 = load i64, i64* %4
%21 = icmp ugt i64 %20, 1048575
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 -2, i32* %2
br label %28
25: ; preds = %19
%26 = load i64, i64* %4
%27 = trunc i64 %26 to i32
store i32 %27, i32* %2
br label %28
28: ; preds = %25, %22, %16
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Error: I2C bus out of range!\0A\00"
define i32 @lookup_i2c_bus(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtoul(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, 1048575
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 ([30 x i8], [30 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
}