#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 /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int);
long strtol(char *, int /*<<< orphan*/ *, int);
void parse_ip(char *buf, char *out) {
  int j;
  char res[5];
  long oct[4];
  for (j = 0; j < 4; j++) {
    bzero(res, sizeof res);
    memcpy(res, buf + j * 2, 2);
    oct[j] = strtol(res, NULL, 16);
  }
  snprintf(out, 16, "%d.%d.%d.%d", (int)oct[0], (int)oct[1], (int)oct[2],
           (int)oct[3]);
}


x86 assembly (clang, -O0):
<parse_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11b8 <parse_ip+0x78>
lea    -0x19(%rbp),%rdi
mov    $0x5,%esi
call   1060 <bzero@plt>
lea    -0x19(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
lea    -0x19(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
mov    %rcx,-0x40(%rbp,%rax,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <parse_ip+0x17>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %eax,%r8d
mov    -0x30(%rbp),%rax
mov    %eax,%r9d
mov    -0x28(%rbp),%rax
mov    $0x10,%esi
lea    0xe20(%rip),%rdx
mov    %eax,(%rsp)
call   1030 <snprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ip>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x13(%rsp),%r15
mov    %r15,%rdi
mov    $0x5,%esi
call   1060 <bzero@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    $0x5,%esi
call   1060 <bzero@plt>
lea    0x2(%rbx),%rsi
mov    %r15,%rdi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,%r13
mov    %r15,%rdi
mov    $0x5,%esi
call   1060 <bzero@plt>
lea    0x4(%rbx),%rsi
mov    %r15,%rdi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,%rbp
mov    %r15,%rdi
mov    $0x5,%esi
call   1060 <bzero@plt>
add    $0x6,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1050 <memcpy@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,(%rsp)
lea    0xdde(%rip),%rdx
mov    %r14,%rdi
mov    $0x10,%esi
mov    %r12d,%ecx
mov    %r13d,%r8d
mov    %ebp,%r9d
call   1030 <snprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define void @parse_ip(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [5 x i8]
%7 = alloca [4 x i64]
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %8
8: ; preds = %26, %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %29
11: ; preds = %8
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%13 = call i32 @bzero(i8* %12, i32 5)
%14 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = mul nsw i32 %16, 2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = call i32 @memcpy(i8* %14, i8* %19, i32 2)
%21 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%22 = call i64 @strtol(i8* %21, i32* null, i32 16)
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [4 x i64], [4 x i64]* %7, i64 0, i64 %24
store i64 %22, i64* %25
br label %26
26: ; preds = %11
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %8
29: ; preds = %8
%30 = load i8*, i8** %4
%31 = getelementptr inbounds [4 x i64], [4 x i64]* %7, i64 0, i64 0
%32 = load i64, i64* %31
%33 = trunc i64 %32 to i32
%34 = getelementptr inbounds [4 x i64], [4 x i64]* %7, i64 0, i64 1
%35 = load i64, i64* %34
%36 = trunc i64 %35 to i32
%37 = getelementptr inbounds [4 x i64], [4 x i64]* %7, i64 0, i64 2
%38 = load i64, i64* %37
%39 = trunc i64 %38 to i32
%40 = getelementptr inbounds [4 x i64], [4 x i64]* %7, i64 0, i64 3
%41 = load i64, i64* %40
%42 = trunc i64 %41 to i32
%43 = call i32 @snprintf(i8* %30, i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %36, i32 %39, i32 %42)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define void @parse_ip(i8* %0, i8* %1) {
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%5 = call i32 @bzero(i8* %4, i32 5)
%6 = call i32 @memcpy(i8* %4, i8* %0, i32 2)
%7 = call i64 @strtol(i8* nocapture %4, i32* null, i32 16)
%8 = call i32 @bzero(i8* %4, i32 5)
%9 = getelementptr inbounds i8, i8* %0, i64 2
%10 = call i32 @memcpy(i8* %4, i8* %9, i32 2)
%11 = call i64 @strtol(i8* nocapture %4, i32* null, i32 16)
%12 = call i32 @bzero(i8* %4, i32 5)
%13 = getelementptr inbounds i8, i8* %0, i64 4
%14 = call i32 @memcpy(i8* %4, i8* %13, i32 2)
%15 = call i64 @strtol(i8* nocapture %4, i32* null, i32 16)
%16 = call i32 @bzero(i8* %4, i32 5)
%17 = getelementptr inbounds i8, i8* %0, i64 6
%18 = call i32 @memcpy(i8* %4, i8* %17, i32 2)
%19 = call i64 @strtol(i8* nocapture %4, i32* null, i32 16)
%20 = trunc i64 %7 to i32
%21 = trunc i64 %11 to i32
%22 = trunc i64 %15 to i32
%23 = trunc i64 %19 to i32
%24 = call i32 @snprintf(i8* %1, i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21, i32 %22, i32 %23)
ret void
}