#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 */
long atoi(char *);
long pow(int, int);
char *strtok(char *, char *);
unsigned int ip2ui(char *ip) {
  long ipAsUInt = 0;
  char *cPtr = strtok(ip, ".");
  if (cPtr)
    ipAsUInt += atoi(cPtr) * pow(256, 3);
  int exponent = 2;
  while (cPtr && exponent >= 0) {
    cPtr = strtok(NULL, ".\0");
    if (cPtr)
      ipAsUInt += atoi(cPtr) * pow(256, exponent--);
  }
  return ipAsUInt;
}


x86 assembly (clang, -O0):
<ip2ui>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1192 <ip2ui+0x62>
mov    -0x18(%rbp),%rdi
call   1050 <atoi@plt>
mov    %rax,-0x28(%rbp)
mov    $0x100,%edi
mov    $0x3,%esi
call   1030 <pow@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
imul   %rcx,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x2,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x29(%rbp)
je     11b3 <ip2ui+0x83>
cmpl   $0x0,-0x1c(%rbp)
setge  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11c3 <ip2ui+0x93>
jmp    121c <ip2ui+0xec>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe34(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1217 <ip2ui+0xe7>
mov    -0x18(%rbp),%rdi
call   1050 <atoi@plt>
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%esi
mov    %esi,%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x100,%edi
call   1030 <pow@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
imul   %rcx,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1199 <ip2ui+0x69>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip2ui>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     1209 <ip2ui+0xd9>
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %rax,%r14
mov    $0x100,%edi
mov    $0x3,%esi
call   1030 <pow@plt>
mov    %rax,%rbx
imul   %r14,%rbx
lea    0xe91(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
test   %rax,%rax
je     120b <ip2ui+0xdb>
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %rax,%r14
mov    $0x100,%edi
mov    $0x2,%esi
call   1030 <pow@plt>
imul   %r14,%rax
add    %rax,%rbx
lea    0xe59(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
test   %rax,%rax
je     120b <ip2ui+0xdb>
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %rax,%r14
mov    $0x100,%edi
mov    $0x1,%esi
call   1030 <pow@plt>
imul   %r14,%rax
add    %rax,%rbx
lea    0xe25(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
test   %rax,%rax
je     120b <ip2ui+0xdb>
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %rax,%r14
mov    $0x100,%edi
xor    %esi,%esi
call   1030 <pow@plt>
imul   %r14,%rax
add    %rax,%rbx
jmp    120b <ip2ui+0xdb>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c".\00\00"
define i32 @ip2ui(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
store i64 0, i64* %3
%6 = load i8*, i8** %2
%7 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = call i64 @atoi(i8* %11)
%13 = call i64 @pow(i32 256, i32 3)
%14 = mul nsw i64 %12, %13
%15 = load i64, i64* %3
%16 = add nsw i64 %15, %14
store i64 %16, i64* %3
br label %17
17: ; preds = %10, %1
store i32 2, i32* %5
br label %18
18: ; preds = %39, %17
%19 = load i8*, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* %5
%23 = icmp sge i32 %22, 0
br label %24
24: ; preds = %21, %18
%25 = phi i1 [ false, %18 ], [ %23, %21 ]
br i1 %25, label %26, label %40
26: ; preds = %24
%27 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %4
%28 = load i8*, i8** %4
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load i8*, i8** %4
%32 = call i64 @atoi(i8* %31)
%33 = load i32, i32* %5
%34 = add nsw i32 %33, -1
store i32 %34, i32* %5
%35 = call i64 @pow(i32 256, i32 %33)
%36 = mul nsw i64 %32, %35
%37 = load i64, i64* %3
%38 = add nsw i64 %37, %36
store i64 %38, i64* %3
br label %39
39: ; preds = %30, %26
br label %18
40: ; preds = %24
%41 = load i64, i64* %3
%42 = trunc i64 %41 to i32
ret i32 %42
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c".\00\00"
define i32 @ip2ui(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 %29, label %4
4: ; preds = %1
%5 = tail call i64 @atoi(i8* %2)
%6 = tail call i64 @pow(i32 256, i32 3)
%7 = mul nsw i64 %6, %5
%8 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %29, label %10
10: ; preds = %4
%11 = tail call i64 @atoi(i8* %8)
%12 = tail call i64 @pow(i32 256, i32 2)
%13 = mul nsw i64 %12, %11
%14 = add nsw i64 %13, %7
%15 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %29, label %17
17: ; preds = %10
%18 = tail call i64 @atoi(i8* %15)
%19 = tail call i64 @pow(i32 256, i32 1)
%20 = mul nsw i64 %19, %18
%21 = add nsw i64 %20, %14
%22 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %29, label %24
24: ; preds = %17
%25 = tail call i64 @atoi(i8* %22)
%26 = tail call i64 @pow(i32 256, i32 0)
%27 = mul nsw i64 %26, %25
%28 = add nsw i64 %27, %21
br label %29
29: ; preds = %4, %10, %17, %24, %1
%30 = phi i64 [ 0, %1 ], [ %7, %4 ], [ %14, %10 ], [ %21, %17 ], [ %28, %24 ]
%31 = trunc i64 %30 to i32
ret i32 %31
}