#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*/ memcpy(void *, char const *, size_t);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, size_t);
void *pig_newseg(size_t);
scalar_t__ strcmp(char const *, char *);
size_t strlen(char const *);
void *to_ipv4(char const *);
void *ipv4_to_voidp(const char *data, size_t *dsize) {
  void *retval = NULL;
  if (data == NULL || dsize == NULL) {
    return NULL;
  }
  if (strcmp(data, "south-american-ip") != 0 &&
      strcmp(data, "north-american-ip") != 0 &&
      strcmp(data, "european-ip") != 0 && strcmp(data, "asian-ip") != 0 &&
      strcmp(data, "user-defined-ip") != 0) {
    retval = pig_newseg(sizeof(unsigned int));
    retval = to_ipv4(data);
    *dsize = sizeof(unsigned int);
  } else {
    *dsize = strlen(data);
    retval = pig_newseg(*dsize + 1);
    memset(retval, 0, *dsize + 1);
    memcpy(retval, data, *dsize);
  }
  return retval;
}


x86 assembly (clang, -O0):
<ipv4_to_voidp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118e <ipv4_to_voidp+0x2e>
cmpq   $0x0,-0x18(%rbp)
jne    119b <ipv4_to_voidp+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    12a1 <ipv4_to_voidp+0x141>
mov    -0x10(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1248 <ipv4_to_voidp+0xe8>
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1248 <ipv4_to_voidp+0xe8>
mov    -0x10(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1248 <ipv4_to_voidp+0xe8>
mov    -0x10(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1248 <ipv4_to_voidp+0xe8>
mov    -0x10(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1248 <ipv4_to_voidp+0xe8>
mov    $0x4,%edi
call   1080 <pig_newseg@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <to_ipv4@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x4,(%rax)
jmp    1299 <ipv4_to_voidp+0x139>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
call   1080 <pig_newseg@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv4_to_voidp>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
test   %rdi,%rdi
je     1231 <ipv4_to_voidp+0xd1>
mov    %rsi,%r14
test   %rsi,%rsi
je     1231 <ipv4_to_voidp+0xd1>
mov    %rdi,%r15
lea    0xe7a(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11fb <ipv4_to_voidp+0x9b>
lea    0xe7b(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11fb <ipv4_to_voidp+0x9b>
lea    0xe79(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11fb <ipv4_to_voidp+0x9b>
lea    0xe71(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11fb <ipv4_to_voidp+0x9b>
lea    0xe66(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11fb <ipv4_to_voidp+0x9b>
mov    $0x4,%edi
call   1080 <pig_newseg@plt>
mov    %r15,%rdi
call   1030 <to_ipv4@plt>
movq   $0x4,(%r14)
jmp    1234 <ipv4_to_voidp+0xd4>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,(%r14)
lea    0x1(%rax),%rdi
call   1080 <pig_newseg@plt>
mov    %rax,%rbx
mov    (%r14),%rdx
add    $0x1,%rdx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    (%r14),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <memcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"south-american-ip\00"
@.str.1 = [18 x i8] c"north-american-ip\00"
@.str.2 = [12 x i8] c"european-ip\00"
@.str.3 = [9 x i8] c"asian-ip\00"
@.str.4 = [16 x i8] c"user-defined-ip\00"
define i8* @ipv4_to_voidp(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
store i8* null, i8** %6
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i64*, i64** %5
%11 = icmp eq i64* %10, null
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store i8* null, i8** %3
br label %58
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %38
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = call i8* @pig_newseg(i64 4)
store i8* %34, i8** %6
%35 = load i8*, i8** %4
%36 = call i8* @to_ipv4(i8* %35)
store i8* %36, i8** %6
%37 = load i64*, i64** %5
store i64 4, i64* %37
br label %56
38: ; preds = %29, %25, %21, %17, %13
%39 = load i8*, i8** %4
%40 = call i64 @strlen(i8* %39)
%41 = load i64*, i64** %5
store i64 %40, i64* %41
%42 = load i64*, i64** %5
%43 = load i64, i64* %42
%44 = add i64 %43, 1
%45 = call i8* @pig_newseg(i64 %44)
store i8* %45, i8** %6
%46 = load i8*, i8** %6
%47 = load i64*, i64** %5
%48 = load i64, i64* %47
%49 = add i64 %48, 1
%50 = call i32 @memset(i8* %46, i32 0, i64 %49)
%51 = load i8*, i8** %6
%52 = load i8*, i8** %4
%53 = load i64*, i64** %5
%54 = load i64, i64* %53
%55 = call i32 @memcpy(i8* %51, i8* %52, i64 %54)
br label %56
56: ; preds = %38, %33
%57 = load i8*, i8** %6
store i8* %57, i8** %3
br label %58
58: ; preds = %56, %12
%59 = load i8*, i8** %3
ret i8* %59
}

LLVM IR (-O2):
@.str = [18 x i8] c"south-american-ip\00"
@.str.1 = [18 x i8] c"north-american-ip\00"
@.str.2 = [12 x i8] c"european-ip\00"
@.str.3 = [9 x i8] c"asian-ip\00"
@.str.4 = [16 x i8] c"user-defined-ip\00"
define i8* @ipv4_to_voidp(i8* %0, i64* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i64* %1, null
%5 = or i1 %3, %4
br i1 %5, label %33, label %6
6: ; preds = %2
%7 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %6
%10 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %24, label %12
12: ; preds = %9
%13 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %12
%16 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i8* @pig_newseg(i64 4)
%23 = tail call i8* @to_ipv4(i8* %0)
store i64 4, i64* %1
br label %33
24: ; preds = %18, %15, %12, %9, %6
%25 = tail call i64 @strlen(i8* dereferenceable(1) %0)
store i64 %25, i64* %1
%26 = add i64 %25, 1
%27 = tail call i8* @pig_newseg(i64 %26)
%28 = load i64, i64* %1
%29 = add i64 %28, 1
%30 = tail call i32 @memset(i8* %27, i32 0, i64 %29)
%31 = load i64, i64* %1
%32 = tail call i32 @memcpy(i8* %27, i8* %0, i64 %31)
br label %33
33: ; preds = %21, %24, %2
%34 = phi i8* [ null, %2 ], [ %23, %21 ], [ %27, %24 ]
ret i8* %34
}