#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 uint32_t;

/* Variables and functions */
int atoi(char *);
char *strtok(char *, char *);
uint32_t ip2int(char *ip) {
  uint32_t result;
  char *p;
  p = strtok(ip, ".");
  if (!p)
    return 0;
  result = atoi(p) * 16777216;
  p = strtok(NULL, ".");
  if (!p)
    return 0;
  result += atoi(p) * 65536;
  p = strtok(NULL, ".");
  if (!p)
    return 0;
  result += atoi(p) * 256;
  p = strtok(NULL, ".");
  if (!p)
    return 0;
  result += atoi(p);
  return result;
}


x86 assembly (clang, -O0):
<ip2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec9(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1157 <ip2int+0x37>
movl   $0x0,-0x4(%rbp)
jmp    1220 <ip2int+0x100>
mov    -0x20(%rbp),%rdi
call   1040 <atoi@plt>
shl    $0x18,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe8f(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1191 <ip2int+0x71>
movl   $0x0,-0x4(%rbp)
jmp    1220 <ip2int+0x100>
mov    -0x20(%rbp),%rdi
call   1040 <atoi@plt>
shl    $0x10,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe52(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ce <ip2int+0xae>
movl   $0x0,-0x4(%rbp)
jmp    1220 <ip2int+0x100>
mov    -0x20(%rbp),%rdi
call   1040 <atoi@plt>
shl    $0x8,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe15(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120b <ip2int+0xeb>
movl   $0x0,-0x4(%rbp)
jmp    1220 <ip2int+0x100>
mov    -0x20(%rbp),%rdi
call   1040 <atoi@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip2int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rsi
call   1030 <strtok@plt>
test   %rax,%rax
je     11b6 <ip2int+0x96>
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,%r14d
lea    0xeb6(%rip),%rsi
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <strtok@plt>
test   %rax,%rax
je     11b8 <ip2int+0x98>
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,%r15d
lea    0xe96(%rip),%rsi
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <strtok@plt>
test   %rax,%rax
je     11b8 <ip2int+0x98>
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,%ebp
lea    0xe77(%rip),%rsi
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <strtok@plt>
test   %rax,%rax
je     11b8 <ip2int+0x98>
shl    $0x18,%r14d
shl    $0x10,%r15d
add    %r14d,%r15d
shl    $0x8,%ebp
add    %r15d,%ebp
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,%ebx
add    %ebp,%ebx
jmp    11b8 <ip2int+0x98>
xor    %ebx,%ebx
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 i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 0, i32* %2
br label %45
11: ; preds = %1
%12 = load i8*, i8** %5
%13 = call i32 @atoi(i8* %12)
%14 = mul nsw i32 %13, 16777216
store i32 %14, i32* %4
%15 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %11
store i32 0, i32* %2
br label %45
19: ; preds = %11
%20 = load i8*, i8** %5
%21 = call i32 @atoi(i8* %20)
%22 = mul nsw i32 %21, 65536
%23 = load i32, i32* %4
%24 = add nsw i32 %23, %22
store i32 %24, i32* %4
%25 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %29, label %28
28: ; preds = %19
store i32 0, i32* %2
br label %45
29: ; preds = %19
%30 = load i8*, i8** %5
%31 = call i32 @atoi(i8* %30)
%32 = mul nsw i32 %31, 256
%33 = load i32, i32* %4
%34 = add nsw i32 %33, %32
store i32 %34, i32* %4
%35 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %35, i8** %5
%36 = load i8*, i8** %5
%37 = icmp ne i8* %36, null
br i1 %37, label %39, label %38
38: ; preds = %29
store i32 0, i32* %2
br label %45
39: ; preds = %29
%40 = load i8*, i8** %5
%41 = call i32 @atoi(i8* %40)
%42 = load i32, i32* %4
%43 = add nsw i32 %42, %41
store i32 %43, i32* %4
%44 = load i32, i32* %4
store i32 %44, i32* %2
br label %45
45: ; preds = %39, %38, %28, %18, %10
%46 = load i32, i32* %2
ret i32 %46
}

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 %24, label %4
4: ; preds = %1
%5 = tail call i32 @atoi(i8* %2)
%6 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %24, label %8
8: ; preds = %4
%9 = tail call i32 @atoi(i8* %6)
%10 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %24, label %12
12: ; preds = %8
%13 = tail call i32 @atoi(i8* %10)
%14 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %24, label %16
16: ; preds = %12
%17 = shl nsw i32 %5, 24
%18 = shl nsw i32 %9, 16
%19 = add nsw i32 %18, %17
%20 = shl nsw i32 %13, 8
%21 = add nsw i32 %19, %20
%22 = tail call i32 @atoi(i8* %14)
%23 = add nsw i32 %21, %22
br label %24
24: ; preds = %12, %8, %4, %1, %16
%25 = phi i32 [ %23, %16 ], [ 0, %1 ], [ 0, %4 ], [ 0, %8 ], [ 0, %12 ]
ret i32 %25
}