#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 */
scalar_t__ isxdigit(char);
unsigned int strlen(char *);
int ishex(char *cp) {
  unsigned int i;
  char c;
  for (i = 0; i <= strlen(cp); i++) {
    c = cp[i];
    if (isxdigit(cp[i]))
      continue;
    else
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ishex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
ja     1195 <ishex+0x75>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%rax
je     117b <ishex+0x5b>
jmp    1187 <ishex+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <ishex+0x7c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1133 <ishex+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ishex>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
xor    %ebp,%ebp
nopl   (%rax)
mov    %ebp,%eax
movsbl (%rbx,%rax,1),%edi
call   1040 <isxdigit@plt>
test   %rax,%rax
je     1153 <ishex+0x33>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jbe    1130 <ishex+0x10>
xor    %eax,%eax
jmp    1158 <ishex+0x38>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ishex(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %3
store i32 0, i32* %4
br label %6
6: ; preds = %26, %1
%7 = load i32, i32* %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp ule i32 %7, %9
br i1 %10, label %11, label %29
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
store i8 %16, i8* %5
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = call i64 @isxdigit(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %11
br label %26
25: ; preds = %11
store i32 -1, i32* %2
br label %30
26: ; preds = %24
%27 = load i32, i32* %4
%28 = add i32 %27, 1
store i32 %28, i32* %4
br label %6
29: ; preds = %6
store i32 0, i32* %2
br label %30
30: ; preds = %29, %25
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @ishex(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
br label %6
3: ; preds = %6
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp ugt i32 %13, %4
br i1 %5, label %14, label %6
6: ; preds = %1, %3
%7 = phi i32 [ 0, %1 ], [ %13, %3 ]
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = tail call i64 @isxdigit(i8 signext %10)
%12 = icmp eq i64 %11, 0
%13 = add i32 %7, 1
br i1 %12, label %14, label %3
14: ; preds = %3, %6
%15 = phi i32 [ -1, %6 ], [ 0, %3 ]
ret i32 %15
}