#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 xtoi(int /*<<< orphan*/);
int get_nibbles(char *src, int n_nibbles) {
  int i;
  int outnum = 0;
  while (n_nibbles-- > 0) {
    if ((i = xtoi(*src++)) == -1)
      return -1;
    outnum = (outnum << 4) | i;
  }
  return outnum;
}


x86 assembly (clang, -O0):
<get_nibbles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    117a <get_nibbles+0x6a>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <xtoi@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1169 <get_nibbles+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    1180 <get_nibbles+0x70>
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1126 <get_nibbles+0x16>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_nibbles>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
jle    1151 <get_nibbles+0x41>
mov    %esi,%ebp
mov    %rdi,%r14
add    $0x1,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%r14),%edi
call   1030 <xtoi@plt>
cmp    $0xffffffff,%eax
je     1155 <get_nibbles+0x45>
add    $0x1,%r14
shl    $0x4,%ebx
or     %eax,%ebx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jg     1130 <get_nibbles+0x20>
jmp    115a <get_nibbles+0x4a>
xor    %ebx,%ebx
jmp    115a <get_nibbles+0x4a>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_nibbles(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %7
br label %8
8: ; preds = %20, %2
%9 = load i32, i32* %5
%10 = add nsw i32 %9, -1
store i32 %10, i32* %5
%11 = icmp sgt i32 %9, 0
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %4
%15 = load i8, i8* %13
%16 = sext i8 %15 to i32
%17 = call i32 @xtoi(i32 %16)
store i32 %17, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 -1, i32* %3
br label %27
20: ; preds = %12
%21 = load i32, i32* %7
%22 = shl i32 %21, 4
%23 = load i32, i32* %6
%24 = or i32 %22, %23
store i32 %24, i32* %7
br label %8
25: ; preds = %8
%26 = load i32, i32* %7
store i32 %26, i32* %3
br label %27
27: ; preds = %25, %19
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @get_nibbles(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %18
4: ; preds = %2, %12
%5 = phi i32 [ %13, %12 ], [ %1, %2 ]
%6 = phi i32 [ %16, %12 ], [ 0, %2 ]
%7 = phi i8* [ %14, %12 ], [ %0, %2 ]
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = tail call i32 @xtoi(i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %18, label %12
12: ; preds = %4
%13 = add nsw i32 %5, -1
%14 = getelementptr inbounds i8, i8* %7, i64 1
%15 = shl i32 %6, 4
%16 = or i32 %10, %15
%17 = icmp sgt i32 %5, 1
br i1 %17, label %4, label %18
18: ; preds = %4, %12, %2
%19 = phi i32 [ 0, %2 ], [ %16, %12 ], [ -1, %4 ]
ret i32 %19
}