#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 */
typedef unsigned int uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void print_ipaddr_len(const uint8_t *addr, uint8_t len) {
  uint16_t a;
  unsigned int i;
  int f;
  for (i = 0, f = 0; i < len; i += 2) {
    a = (addr[i] << 8) + addr[i + 1];
    if (a == 0 && f >= 0) {
      if (f++ == 0) {
        printf("::");
      }
    } else {
      if (f > 0) {
        f = -1;
      } else if (i > 0) {
        printf(":");
      }
      printf("%x", a);
    }
  }
}


x86 assembly (clang, -O0):
<print_ipaddr_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11ea <print_ipaddr_len+0xda>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
mov    -0x14(%rbp),%edx
add    $0x1,%edx
mov    %edx,%edx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1193 <print_ipaddr_len+0x83>
cmpl   $0x0,-0x18(%rbp)
jl     1193 <print_ipaddr_len+0x83>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
jne    118e <print_ipaddr_len+0x7e>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d7 <print_ipaddr_len+0xc7>
cmpl   $0x0,-0x18(%rbp)
jle    11a9 <print_ipaddr_len+0x99>
movl   $0xffffffff,-0x18(%rbp)
jmp    11c6 <print_ipaddr_len+0xb6>
cmpl   $0x0,-0x14(%rbp)
jbe    11c1 <print_ipaddr_len+0xb1>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c6 <print_ipaddr_len+0xb6>
mov    -0x10(%rbp),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11dc <print_ipaddr_len+0xcc>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    112d <print_ipaddr_len+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ipaddr_len>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     11b0 <print_ipaddr_len+0x90>
mov    %esi,%r12d
mov    %rdi,%r13
xor    %r14d,%r14d
xor    %ebx,%ebx
jmp    1166 <print_ipaddr_len+0x46>
mov    $0xffffffff,%r15d
test   %r14d,%r14d
jle    1187 <print_ipaddr_len+0x67>
lea    0xeb1(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%r14d
add    $0x2,%ebx
cmp    %r12d,%ebx
jae    11b0 <print_ipaddr_len+0x90>
mov    %ebx,%eax
mov    0x0(%r13,%rax,4),%ebp
shl    $0x8,%ebp
lea    0x1(%rbx),%eax
add    0x0(%r13,%rax,4),%ebp
jne    1140 <print_ipaddr_len+0x20>
test   %r14d,%r14d
js     1140 <print_ipaddr_len+0x20>
je     119a <print_ipaddr_len+0x7a>
add    $0x1,%r14d
jmp    115e <print_ipaddr_len+0x3e>
test   %ebx,%ebx
je     1195 <print_ipaddr_len+0x75>
mov    $0x3a,%edi
call   1030 <putchar@plt>
mov    %r14d,%r15d
jmp    114b <print_ipaddr_len+0x2b>
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
jmp    115e <print_ipaddr_len+0x3e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"::\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [3 x i8] c"%x\00"
define void @print_ipaddr_len(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %52, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %55
12: ; preds = %8
%13 = load i32*, i32** %3
%14 = load i32, i32* %6
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = shl i32 %17, 8
%19 = load i32*, i32** %3
%20 = load i32, i32* %6
%21 = add i32 %20, 1
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %19, i64 %22
%24 = load i32, i32* %23
%25 = add i32 %18, %24
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %12
%29 = load i32, i32* %7
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
%34 = icmp eq i32 %32, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
br label %51
38: ; preds = %28, %12
%39 = load i32, i32* %7
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 -1, i32* %7
br label %48
42: ; preds = %38
%43 = load i32, i32* %6
%44 = icmp ugt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45, %42
br label %48
48: ; preds = %47, %41
%49 = load i32, i32* %5
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %48, %37
br label %52
52: ; preds = %51
%53 = load i32, i32* %6
%54 = add i32 %53, 2
store i32 %54, i32* %6
br label %8
55: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"::\00"
@.str.2 = [3 x i8] c"%x\00"
define void @print_ipaddr_len(i32* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %37, label %4
4: ; preds = %2, %33
%5 = phi i32 [ %34, %33 ], [ 0, %2 ]
%6 = phi i32 [ %35, %33 ], [ 0, %2 ]
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = load i32, i32* %8
%10 = shl i32 %9, 8
%11 = or i32 %6, 1
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = add i32 %10, %14
%16 = icmp eq i32 %15, 0
%17 = icmp sgt i32 %5, -1
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %19, label %24
19: ; preds = %4
%20 = add nuw nsw i32 %5, 1
%21 = icmp eq i32 %5, 0
br i1 %21, label %22, label %33
22: ; preds = %19
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %33
24: ; preds = %4
%25 = icmp sgt i32 %5, 0
br i1 %25, label %30, label %26
26: ; preds = %24
%27 = icmp eq i32 %6, 0
br i1 %27, label %30, label %28
28: ; preds = %26
%29 = tail call i32 @putchar(i32 58)
br label %30
30: ; preds = %24, %26, %28
%31 = phi i32 [ %5, %28 ], [ %5, %26 ], [ -1, %24 ]
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %33
33: ; preds = %30, %22, %19
%34 = phi i32 [ 1, %22 ], [ %20, %19 ], [ %31, %30 ]
%35 = add i32 %6, 2
%36 = icmp ult i32 %35, %1
br i1 %36, label %4, label %37
37: ; preds = %33, %2
ret void
}