#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 int /*<<< orphan*/ oct;

/* Variables and functions */
unsigned int atoi(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ pig_newseg(int);
unsigned int *to_ipv4(const char *data) {
  unsigned int *retval = NULL;
  const char *dp = NULL;
  char oct[20];
  size_t o = 0;
  if (data == NULL) {
    return NULL;
  }
  retval = (unsigned int *)pig_newseg(sizeof(unsigned int));
  *retval = 0;
  memset(oct, 0, sizeof(oct));
  for (dp = data; *dp != 0; dp++) {
    if (*dp == '.' || *(dp + 1) == 0) {
      if (*(dp + 1) == 0) {
        oct[o] = *dp;
      }
      *retval = ((*retval) << 8) | atoi(oct);
      o = 0;
      memset(oct, 0, sizeof(oct));
    } else {
      oct[o] = *dp;
      o = (o + 1) % sizeof(oct);
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<to_ipv4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x48(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116c <to_ipv4+0x3c>
movq   $0x0,-0x8(%rbp)
jmp    126b <to_ipv4+0x13b>
mov    $0x4,%edi
call   1040 <pig_newseg@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1263 <to_ipv4+0x133>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11cd <to_ipv4+0x9d>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1229 <to_ipv4+0xf9>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    11ec <to_ipv4+0xbc>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x48(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
shl    $0x8,%eax
mov    %eax,-0x4c(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <atoi@plt>
mov    -0x4c(%rbp),%ecx
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
jmp    124d <to_ipv4+0x11d>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x48(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    $0x14,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x48(%rbp)
jmp    1252 <to_ipv4+0x122>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    119c <to_ipv4+0x6c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_ipv4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     1207 <to_ipv4+0xd7>
mov    %rdi,%rbx
mov    $0x4,%edi
call   1040 <pig_newseg@plt>
mov    %rax,%r14
movl   $0x0,(%rax)
mov    %rsp,%r15
xor    %r13d,%r13d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
add    $0x1,%rbx
movabs $0xcccccccccccccccd,%r12
cc cc cc
jmp    11bd <to_ipv4+0x8d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %al,(%rsp,%r13,1)
mov    (%r14),%ebp
shl    $0x8,%ebp
mov    %r15,%rdi
call   1050 <atoi@plt>
or     %ebp,%eax
mov    %eax,(%r14)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
add    $0x1,%rbx
xor    %r13d,%r13d
movzbl -0x1(%rbx),%eax
cmp    $0x2e,%al
je     1200 <to_ipv4+0xd0>
test   %al,%al
je     120a <to_ipv4+0xda>
cmpb   $0x0,(%rbx)
je     1190 <to_ipv4+0x60>
mov    %al,(%rsp,%r13,1)
lea    0x1(%r13),%rax
mul    %r12
shr    $0x2,%rdx
and    $0xfffffffffffffffc,%rdx
lea    (%rdx,%rdx,4),%rax
neg    %rax
add    %rax,%r13
add    $0x1,%r13
add    $0x1,%rbx
jmp    11bd <to_ipv4+0x8d>
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x0,(%rbx)
jne    1194 <to_ipv4+0x64>
jmp    1190 <to_ipv4+0x60>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @to_ipv4(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [20 x i8]
%7 = alloca i64
store i8* %0, i8** %3
store i32* null, i32** %4
store i8* null, i8** %5
store i64 0, i64* %7
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32* null, i32** %2
br label %69
11: ; preds = %1
%12 = call i64 @pig_newseg(i32 4)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %4
%14 = load i32*, i32** %4
store i32 0, i32* %14
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 20)
%17 = load i8*, i8** %3
store i8* %17, i8** %5
br label %18
18: ; preds = %64, %11
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %67
23: ; preds = %18
%24 = load i8*, i8** %5
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 46
br i1 %27, label %34, label %28
28: ; preds = %23
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %55
34: ; preds = %28, %23
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %34
%41 = load i8*, i8** %5
%42 = load i8, i8* %41
%43 = load i64, i64* %7
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 %43
store i8 %42, i8* %44
br label %45
45: ; preds = %40, %34
%46 = load i32*, i32** %4
%47 = load i32, i32* %46
%48 = shl i32 %47, 8
%49 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%50 = call i32 @atoi(i8* %49)
%51 = or i32 %48, %50
%52 = load i32*, i32** %4
store i32 %51, i32* %52
store i64 0, i64* %7
%53 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%54 = call i32 @memset(i8* %53, i32 0, i32 20)
br label %63
55: ; preds = %28
%56 = load i8*, i8** %5
%57 = load i8, i8* %56
%58 = load i64, i64* %7
%59 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 %58
store i8 %57, i8* %59
%60 = load i64, i64* %7
%61 = add i64 %60, 1
%62 = urem i64 %61, 20
store i64 %62, i64* %7
br label %63
63: ; preds = %55, %45
br label %64
64: ; preds = %63
%65 = load i8*, i8** %5
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %5
br label %18
67: ; preds = %18
%68 = load i32*, i32** %4
store i32* %68, i32** %2
br label %69
69: ; preds = %67, %10
%70 = load i32*, i32** %2
ret i32* %70
}

LLVM IR (-O2):
define i32* @to_ipv4(i8* %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %36, label %5
5: ; preds = %1
%6 = tail call i64 @pig_newseg(i32 4)
%7 = inttoptr i64 %6 to i32*
store i32 0, i32* %7
%8 = call i32 @memset(i8* %3, i32 0, i32 20)
br label %9
9: ; preds = %33, %5
%10 = phi i8* [ %0, %5 ], [ %35, %33 ]
%11 = phi i64 [ 0, %5 ], [ %34, %33 ]
%12 = load i8, i8* %10
switch i8 %12, label %13 [
i8 0, label %36
i8 46, label %17
]
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %21, label %29
17: ; preds = %9
%18 = getelementptr inbounds i8, i8* %10, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13, %17
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %11
store i8 %12, i8* %22
br label %23
23: ; preds = %21, %17
%24 = load i32, i32* %7
%25 = shl i32 %24, 8
%26 = call i32 @atoi(i8* %3)
%27 = or i32 %25, %26
store i32 %27, i32* %7
%28 = call i32 @memset(i8* %3, i32 0, i32 20)
br label %33
29: ; preds = %13
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %11
store i8 %12, i8* %30
%31 = add nsw i64 %11, 1
%32 = urem i64 %31, 20
br label %33
33: ; preds = %23, %29
%34 = phi i64 [ 0, %23 ], [ %32, %29 ]
%35 = getelementptr inbounds i8, i8* %10, i64 1
br label %9
36: ; preds = %9, %1
%37 = phi i32* [ null, %1 ], [ %7, %9 ]
ret i32* %37
}