#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 scan_fromhex(int /*<<< orphan*/);
unsigned int scan_ip6_flat(const char *s, char ip[16]) {
  int i;
  for (i = 0; i < 16; i++) {
    int tmp;
    tmp = scan_fromhex(*s++);
    if (tmp < 0)
      return 0;
    ip[i] = tmp << 4;
    tmp = scan_fromhex(*s++);
    if (tmp < 0)
      return 0;
    ip[i] += tmp;
  }
  return 32;
}


x86 assembly (clang, -O0):
<scan_ip6_flat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    11c6 <scan_ip6_flat+0xb6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <scan_fromhex@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1161 <scan_ip6_flat+0x51>
movl   $0x0,-0x4(%rbp)
jmp    11cd <scan_ip6_flat+0xbd>
mov    -0x20(%rbp),%eax
shl    $0x4,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <scan_fromhex@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11a4 <scan_ip6_flat+0x94>
movl   $0x0,-0x4(%rbp)
jmp    11cd <scan_ip6_flat+0xbd>
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
add    %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1127 <scan_ip6_flat+0x17>
movl   $0x20,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_ip6_flat>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
xor    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r12,%rbx,2),%edi
call   1030 <scan_fromhex@plt>
test   %eax,%eax
js     1168 <scan_ip6_flat+0x58>
shl    $0x4,%al
mov    %al,(%r15,%rbx,1)
movsbl 0x1(%r12,%rbx,2),%edi
call   1030 <scan_fromhex@plt>
test   %eax,%eax
js     1168 <scan_ip6_flat+0x58>
add    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    $0x10,%rbx
jne    1130 <scan_ip6_flat+0x20>
mov    $0x20,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @scan_ip6_flat(i8* nocapture %0, i8* nocapture %1) {
br label %3
3: ; preds = %2, %19
%4 = phi i64 [ 0, %2 ], [ %24, %19 ]
%5 = phi i8* [ %0, %2 ], [ %20, %19 ]
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = tail call i32 @scan_fromhex(i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %3
%11 = getelementptr inbounds i8, i8* %5, i64 1
%12 = trunc i32 %8 to i8
%13 = shl i8 %12, 4
%14 = getelementptr inbounds i8, i8* %1, i64 %4
store i8 %13, i8* %14
%15 = load i8, i8* %11
%16 = sext i8 %15 to i32
%17 = tail call i32 @scan_fromhex(i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %10
%20 = getelementptr inbounds i8, i8* %5, i64 2
%21 = load i8, i8* %14
%22 = trunc i32 %17 to i8
%23 = add i8 %21, %22
store i8 %23, i8* %14
%24 = add nuw nsw i64 %4, 1
%25 = icmp eq i64 %24, 16
br i1 %25, label %26, label %3
26: ; preds = %10, %3, %19
%27 = phi i32 [ 32, %19 ], [ 0, %3 ], [ 0, %10 ]
ret i32 %27
}