#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 /*<<< orphan*/ stderr;
long strtol(char const *, char **, int /*<<< orphan*/);
int parse_i2c_address(const char *address_arg) {
  long address;
  char *end;
  address = strtol(address_arg, &end, 0);
  if (*end || !*address_arg) {
    fprintf(stderr, "Error: Chip address is not a number!\n");
    return -1;
  }
  if (address < 0x03 || address > 0x77) {
    fprintf(stderr, "Error: Chip address out of range "
                    "(0x03-0x77)!\n");
    return -2;
  }
  return address;
}


x86 assembly (clang, -O0):
<parse_i2c_address>:
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    115c <parse_i2c_address+0x3c>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    117d <parse_i2c_address+0x5d>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <parse_i2c_address+0x9b>
cmpq   $0x3,-0x18(%rbp)
jl     1193 <parse_i2c_address+0x73>
cmpq   $0x77,-0x18(%rbp)
jle    11b4 <parse_i2c_address+0x94>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11bb <parse_i2c_address+0x9b>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_i2c_address>:
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     115e <parse_i2c_address+0x3e>
mov    0x2e9b(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
cmpb   $0x0,(%rbx)
je     113e <parse_i2c_address+0x1e>
lea    -0x78(%rax),%rcx
cmp    $0xffffffffffffff8a,%rcx
ja     1158 <parse_i2c_address+0x38>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xfffffffe,%eax
jmp    1158 <parse_i2c_address+0x38>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"Error: Chip address is not a number!\0A\00"
@.str.1 = [47 x i8] c"Error: Chip address out of range (0x03-0x77)!\0A\00"
define i32 @parse_i2c_address(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 i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %31
19: ; preds = %12
%20 = load i64, i64* %4
%21 = icmp slt i64 %20, 3
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i64, i64* %4
%24 = icmp sgt i64 %23, 119
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 ([47 x i8], [47 x i8]* @.str.1, 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: Chip address is not a number!\0A\00"
@.str.1 = [47 x i8] c"Error: Chip address out of range (0x03-0x77)!\0A\00"
define i32 @parse_i2c_address(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 %14
11: ; preds = %8, %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %22
14: ; preds = %8
%15 = add i64 %4, -120
%16 = icmp ult i64 %15, -117
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %22
20: ; preds = %14
%21 = trunc i64 %4 to i32
br label %22
22: ; preds = %20, %17, %11
%23 = phi i32 [ -1, %11 ], [ -2, %17 ], [ %21, %20 ]
ret i32 %23
}