#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 */
struct in6_addr {
  int *s6_addr;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int INET6_ADDRSTRLEN;
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, struct in6_addr *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ trim(char *);
void hex2dec(FILE *f) {
  struct in6_addr addr;
  char buf[10 * INET6_ADDRSTRLEN];
  int i;
  while (fgets(buf, sizeof(buf), f) && trim(buf) &&
         inet_pton(AF_INET6, buf, &addr) > 0) {
    for (i = 0; i < 16; i++) {
      printf("%03d:", addr.s6_addr[i]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<hex2dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%ecx
add    %ecx,%ecx
mov    %ecx,%eax
lea    (%rax,%rax,4),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x39(%rbp)
je     11e3 <hex2dec+0xa3>
mov    -0x30(%rbp),%rdi
call   1040 <trim@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x39(%rbp)
je     11e3 <hex2dec+0xa3>
mov    -0x30(%rbp),%rsi
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rdx
call   1060 <inet_pton@plt>
cmp    $0x0,%rax
setg   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11f3 <hex2dec+0xb3>
jmp    123e <hex2dec+0xfe>
movl   $0x0,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    122b <hex2dec+0xeb>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11fa <hex2dec+0xba>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1183 <hex2dec+0x43>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2dec>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
mov    %rsp,-0x38(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
lea    (%rax,%rax,4),%r15d
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    %r13,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     130e <hex2dec+0x1be>
lea    -0x30(%rbp),%r12
lea    0xe56(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1050 <trim@plt>
test   %rax,%rax
je     130e <hex2dec+0x1be>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   1070 <inet_pton@plt>
test   %rax,%rax
jle    130e <hex2dec+0x1be>
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x18(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x1c(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x20(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x24(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x28(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x2c(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x30(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x34(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x38(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x3c(%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13,%rdi
mov    %r15d,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11b0 <hex2dec+0x60>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32* }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i32 0
@.str = [6 x i8] c"%03d:\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @hex2dec(i32* %0) {
%2 = alloca i32*
%3 = alloca %struct.in6_addr
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %2
%7 = load i32, i32* @INET6_ADDRSTRLEN
%8 = mul nsw i32 10, %7
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i8, i64 %9
store i64 %9, i64* %5
br label %12
12: ; preds = %41, %1
%13 = trunc i64 %9 to i32
%14 = load i32*, i32** %2
%15 = call i64 @fgets(i8* %11, i32 %13, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = call i64 @trim(i8* %11)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @AF_INET6
%22 = call i64 @inet_pton(i32 %21, i8* %11, %struct.in6_addr* %3)
%23 = icmp sgt i64 %22, 0
br label %24
24: ; preds = %20, %17, %12
%25 = phi i1 [ false, %17 ], [ false, %12 ], [ %23, %20 ]
br i1 %25, label %26, label %43
26: ; preds = %24
store i32 0, i32* %6
br label %27
27: ; preds = %38, %26
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 16
br i1 %29, label %30, label %41
30: ; preds = %27
%31 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %3, i32 0, i32 0
%32 = load i32*, i32** %31
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %30
%39 = load i32, i32* %6
%40 = add nsw i32 %39, 1
store i32 %40, i32* %6
br label %27
41: ; preds = %27
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %12
43: ; preds = %24
%44 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
%struct.in6_addr = type { i32* }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i32 0
@.str = [6 x i8] c"%03d:\00"
define void @hex2dec(i32* nocapture %0) {
%2 = alloca %struct.in6_addr
%3 = bitcast %struct.in6_addr* %2 to i8*
%4 = load i32, i32* @INET6_ADDRSTRLEN
%5 = mul nsw i32 %4, 10
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = call i64 @fgets(i8* %8, i32 %5, i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %87, label %11
11: ; preds = %1
%12 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %2, i64 0, i32 0
br label %13
13: ; preds = %11, %20
%14 = call i64 @trim(i8* %8)
%15 = icmp eq i64 %14, 0
br i1 %15, label %87, label %16
16: ; preds = %13
%17 = load i32, i32* @AF_INET6
%18 = call i64 @inet_pton(i32 %17, i8* %8, %struct.in6_addr* %2)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %87
20: ; preds = %16
%21 = load i32*, i32** %12
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i32*, i32** %12
%25 = getelementptr inbounds i32, i32* %24, i64 1
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i32*, i32** %12
%29 = getelementptr inbounds i32, i32* %28, i64 2
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load i32*, i32** %12
%33 = getelementptr inbounds i32, i32* %32, i64 3
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = load i32*, i32** %12
%37 = getelementptr inbounds i32, i32* %36, i64 4
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = load i32*, i32** %12
%41 = getelementptr inbounds i32, i32* %40, i64 5
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = load i32*, i32** %12
%45 = getelementptr inbounds i32, i32* %44, i64 6
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %46)
%48 = load i32*, i32** %12
%49 = getelementptr inbounds i32, i32* %48, i64 7
%50 = load i32, i32* %49
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %50)
%52 = load i32*, i32** %12
%53 = getelementptr inbounds i32, i32* %52, i64 8
%54 = load i32, i32* %53
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %54)
%56 = load i32*, i32** %12
%57 = getelementptr inbounds i32, i32* %56, i64 9
%58 = load i32, i32* %57
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %58)
%60 = load i32*, i32** %12
%61 = getelementptr inbounds i32, i32* %60, i64 10
%62 = load i32, i32* %61
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %62)
%64 = load i32*, i32** %12
%65 = getelementptr inbounds i32, i32* %64, i64 11
%66 = load i32, i32* %65
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %66)
%68 = load i32*, i32** %12
%69 = getelementptr inbounds i32, i32* %68, i64 12
%70 = load i32, i32* %69
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %70)
%72 = load i32*, i32** %12
%73 = getelementptr inbounds i32, i32* %72, i64 13
%74 = load i32, i32* %73
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %74)
%76 = load i32*, i32** %12
%77 = getelementptr inbounds i32, i32* %76, i64 14
%78 = load i32, i32* %77
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %78)
%80 = load i32*, i32** %12
%81 = getelementptr inbounds i32, i32* %80, i64 15
%82 = load i32, i32* %81
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %82)
%84 = call i32 @putchar(i32 10)
%85 = call i64 @fgets(i8* %8, i32 %5, i32* %0)
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %13
87: ; preds = %16, %13, %20, %1
ret void
}