#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 atoi(char *);
int pow(int, int);
char *strtok(char *, char *);
unsigned int ip2int(char *ipStr) {
  unsigned int ipInt = 0;
  int tokenInt = 0;
  char *token;
  token = strtok(ipStr, ".");
  int i = 3;
  while (token != NULL) {
    tokenInt = atoi(token);
    ipInt += tokenInt * pow(256, i);
    token = strtok(NULL, ".");
    i--;
  }
  return ipInt;
}


x86 assembly (clang, -O0):
<ip2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
movl   $0x3,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11bf <ip2int+0x8f>
mov    -0x18(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
mov    $0x100,%edi
call   1030 <pow@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
imul   %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe58(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1165 <ip2int+0x35>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip2int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rsi
call   1040 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     118f <ip2int+0x5f>
mov    $0x3,%ebp
lea    0xeaa(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %eax,%r15d
mov    $0x100,%edi
mov    %ebp,%esi
call   1030 <pow@plt>
imul   %r15d,%eax
add    %eax,%ebx
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    1160 <ip2int+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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