#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 strtol(char *, char **, int);
int Url_decode_hex_octet(const char *s) {
  int hex_value;
  char *tail, hex[3];
  if (s && (hex[0] = s[0]) && (hex[1] = s[1])) {
    hex[2] = 0;
    hex_value = strtol(hex, &tail, 16);
    if (tail - hex == 2)
      return hex_value;
  }
  return -1;
}


x86 assembly (clang, -O0):
<Url_decode_hex_octet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1190 <Url_decode_hex_octet+0x80>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x23(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     1190 <Url_decode_hex_octet+0x80>
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x22(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     1190 <Url_decode_hex_octet+0x80>
movb   $0x0,-0x21(%rbp)
lea    -0x23(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
lea    -0x23(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x2,%rax
jne    118b <Url_decode_hex_octet+0x7b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1197 <Url_decode_hex_octet+0x87>
jmp    1190 <Url_decode_hex_octet+0x80>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Url_decode_hex_octet>:
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     1159 <Url_decode_hex_octet+0x49>
mov    (%rdi),%al
mov    %al,0x5(%rsp)
test   %al,%al
je     1159 <Url_decode_hex_octet+0x49>
mov    0x1(%rdi),%al
mov    %al,0x6(%rsp)
test   %al,%al
je     1159 <Url_decode_hex_octet+0x49>
movb   $0x0,0x7(%rsp)
lea    0x5(%rsp),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    0x8(%rsp),%rcx
sub    %rbx,%rcx
cmp    $0x2,%rcx
je     115e <Url_decode_hex_octet+0x4e>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @Url_decode_hex_octet(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [3 x i8]
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %36
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
store i8 %12, i8* %13
%14 = sext i8 %12 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %36
16: ; preds = %9
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 1
store i8 %19, i8* %20
%21 = sext i8 %19 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %16
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 2
store i8 0, i8* %24
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%26 = call i32 @strtol(i8* %25, i8** %5, i32 16)
store i32 %26, i32* %4
%27 = load i8*, i8** %5
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = icmp eq i64 %31, 2
br i1 %32, label %33, label %35
33: ; preds = %23
%34 = load i32, i32* %4
store i32 %34, i32* %2
br label %37
35: ; preds = %23
br label %36
36: ; preds = %35, %16, %9, %1
store i32 -1, i32* %2
br label %37
37: ; preds = %36, %33
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @Url_decode_hex_octet(i8* %0) {
%2 = alloca i8*
%3 = alloca [3 x i8]
%4 = bitcast i8** %2 to i8*
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %23, label %7
7: ; preds = %1
%8 = load i8, i8* %0
store i8 %8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = load i8, i8* %11
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
store i8 %12, i8* %13
%14 = icmp eq i8 %12, 0
br i1 %14, label %23, label %15
15: ; preds = %10
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %16
%17 = call i32 @strtol(i8* %5, i8** %2, i32 16)
%18 = load i8*, i8** %2
%19 = ptrtoint i8* %18 to i64
%20 = ptrtoint [3 x i8]* %3 to i64
%21 = sub i64 %19, %20
%22 = icmp eq i64 %21, 2
br i1 %22, label %24, label %23
23: ; preds = %15, %10, %7, %1
br label %24
24: ; preds = %15, %23
%25 = phi i32 [ -1, %23 ], [ %17, %15 ]
ret i32 %25
}