#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*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
scalar_t__ malloc(int);
scalar_t__ strtok(char *, char *);
uint8_t *parseip(char *str) {
  uint8_t *ret = (uint8_t *)malloc(4 * sizeof(uint8_t));
  char *num = (char *)strtok(str, ".");
  int index = 0;
  while (num != NULL) {
    ret[index++] = atoi(num);
    num = (char *)strtok(NULL, ".");
  }
  return ret;
}


x86 assembly (clang, -O0):
<parseip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x10,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a9 <parseip+0x79>
mov    -0x18(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe65(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1165 <parseip+0x35>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseip>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x10,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strtok@plt>
test   %rax,%rax
je     118d <parseip+0x5d>
lea    0xea0(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %eax,(%rbx)
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
add    $0x4,%rbx
test   %rax,%rax
jne    1170 <parseip+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i32* @parseip(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i64 @malloc(i32 16)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %3
%8 = load i8*, i8** %2
%9 = call i64 @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %4
store i32 0, i32* %5
br label %11
11: ; preds = %14, %1
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = call i32 @atoi(i8* %15)
%17 = load i32*, i32** %3
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i32, i32* %17, i64 %20
store i32 %16, i32* %21
%22 = call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %4
br label %11
24: ; preds = %11
%25 = load i32*, i32** %3
ret i32* %25
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32* @parseip(i8* %0) {
%2 = tail call i64 @malloc(i32 16)
%3 = inttoptr i64 %2 to i32*
%4 = tail call i64 @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %11, %6 ], [ 0, %1 ]
%8 = phi i64 [ %13, %6 ], [ %4, %1 ]
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @atoi(i8* %9)
%11 = add nuw i64 %7, 1
%12 = getelementptr inbounds i32, i32* %3, i64 %7
store i32 %10, i32* %12
%13 = tail call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %6, %1
ret i32* %3
}