#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*/ bzero(char *, int);
int hex2bin(char *);
int strlen(char *);
int gpsd_hexpack(char *src, char *dst, int len) {
  int i, k, l;
  l = (int)(strlen(src) / 2);
  if ((l < 1) || (l > len))
    return -1;
  bzero(dst, len);
  for (i = 0; i < l; i++)
    if ((k = hex2bin(src + i * 2)) != -1)
      dst[i] = (char)(k & 0xff);
    else
      return -1;
  return l;
}


x86 assembly (clang, -O0):
<gpsd_hexpack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
cmpl   $0x1,-0x28(%rbp)
jl     116d <gpsd_hexpack+0x3d>
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1179 <gpsd_hexpack+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <gpsd_hexpack+0xc7>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <bzero@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11f1 <gpsd_hexpack+0xc1>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
call   1030 <hex2bin@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     11d2 <gpsd_hexpack+0xa2>
mov    -0x24(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11de <gpsd_hexpack+0xae>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <gpsd_hexpack+0xc7>
jmp    11e3 <gpsd_hexpack+0xb3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118c <gpsd_hexpack+0x5c>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpsd_hexpack>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,%rbp
call   1040 <strlen@plt>
mov    $0xffffffff,%r14d
cmp    $0x2,%eax
jl     11a2 <gpsd_hexpack+0x72>
mov    %eax,%r12d
shr    $0x1f,%r12d
add    %eax,%r12d
sar    %r12d
cmp    %r15d,%r12d
jg     11a2 <gpsd_hexpack+0x72>
mov    %r13,%rdi
mov    %r15d,%esi
call   1050 <bzero@plt>
mov    %r12d,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1030 <hex2bin@plt>
cmp    $0xffffffff,%eax
je     11a2 <gpsd_hexpack+0x72>
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
add    $0x2,%rbp
cmp    %rbx,%r15
jne    1180 <gpsd_hexpack+0x50>
mov    %r12d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gpsd_hexpack(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = sdiv i32 %12, 2
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp slt i32 %14, 1
br i1 %15, label %20, label %16
16: ; preds = %3
%17 = load i32, i32* %10
%18 = load i32, i32* %7
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16, %3
store i32 -1, i32* %4
br label %52
21: ; preds = %16
%22 = load i8*, i8** %6
%23 = load i32, i32* %7
%24 = call i32 @bzero(i8* %22, i32 %23)
store i32 0, i32* %8
br label %25
25: ; preds = %47, %21
%26 = load i32, i32* %8
%27 = load i32, i32* %10
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %50
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = load i32, i32* %8
%32 = mul nsw i32 %31, 2
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = call i32 @hex2bin(i8* %34)
store i32 %35, i32* %9
%36 = icmp ne i32 %35, -1
br i1 %36, label %37, label %45
37: ; preds = %29
%38 = load i32, i32* %9
%39 = and i32 %38, 255
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %6
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 %40, i8* %44
br label %46
45: ; preds = %29
store i32 -1, i32* %4
br label %52
46: ; preds = %37
br label %47
47: ; preds = %46
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %25
50: ; preds = %25
%51 = load i32, i32* %10
store i32 %51, i32* %4
br label %52
52: ; preds = %50, %45, %20
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
define i32 @gpsd_hexpack(i8* %0, i8* nocapture writeonly %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = sdiv i32 %4, 2
%6 = icmp slt i32 %4, 2
%7 = icmp sgt i32 %5, %2
%8 = or i1 %6, %7
br i1 %8, label %23, label %9
9: ; preds = %3
%10 = tail call i32 @bzero(i8* %1, i32 %2)
%11 = zext i32 %5 to i64
br label %12
12: ; preds = %9, %18
%13 = phi i64 [ 0, %9 ], [ %21, %18 ]
%14 = shl nuw nsw i64 %13, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = tail call i32 @hex2bin(i8* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %23, label %18
18: ; preds = %12
%19 = trunc i32 %16 to i8
%20 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %19, i8* %20
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %23, label %12
23: ; preds = %12, %18, %3
%24 = phi i32 [ -1, %3 ], [ -1, %12 ], [ %5, %18 ]
ret i32 %24
}