#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*/ error(int, int /*<<< orphan*/, char *, ...);
unsigned int strtoul(char const *, char **, int /*<<< orphan*/);
unsigned int parse_gpio_pin(const char *pin_str) {
  char *endp;
  unsigned int pin;
  if (pin_str[0] == '\0') {
    error(2, 0, "empty string given for GPIO pin number");
  }
  pin = strtoul(pin_str, &endp, 0);
  if (*endp != '\0') {
    error(2, 0, "%s is not a valid GPIO pin number", pin_str);
  }
  return pin;
}


x86 assembly (clang, -O0):
<parse_gpio_pin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1151 <parse_gpio_pin+0x31>
mov    $0x2,%edi
xor    %esi,%esi
lea    0xeb6(%rip),%rdx
mov    $0x0,%al
call   1030 <error@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118c <parse_gpio_pin+0x6c>
mov    -0x8(%rbp),%rcx
mov    $0x2,%edi
xor    %esi,%esi
lea    0xea2(%rip),%rdx
mov    $0x0,%al
call   1030 <error@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_gpio_pin>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
jne    1140 <parse_gpio_pin+0x20>
lea    0xece(%rip),%rdx
mov    $0x2,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <error@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %eax,%ebp
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     1170 <parse_gpio_pin+0x50>
lea    0xec8(%rip),%rdx
mov    $0x2,%edi
xor    %esi,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <error@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"empty string given for GPIO pin number\00"
@.str.1 = [34 x i8] c"%s is not a valid GPIO pin number\00"
define i32 @parse_gpio_pin(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 (i32, i32, i8*, ...) @error(i32 2, i32 0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = load i8*, i8** %2
%14 = call i32 @strtoul(i8* %13, i8** %3, i32 0)
store i32 %14, i32* %4
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i8*, i8** %2
%21 = call i32 (i32, i32, i8*, ...) @error(i32 2, i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %12
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@.str = [39 x i8] c"empty string given for GPIO pin number\00"
@.str.1 = [34 x i8] c"%s is not a valid GPIO pin number\00"
define i32 @parse_gpio_pin(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (i32, i32, i8*, ...) @error(i32 2, i32 0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = call i32 @strtoul(i8* %0, i8** %2, i32 0)
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i32 (i32, i32, i8*, ...) @error(i32 2, i32 0, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %13, %8
ret i32 %9
}