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

/* Variables and functions */
int atoi(char *);
int pow(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strtok(char *, char *);
uint64_t ip2int(const char *ipconvertint) {
  uint64_t final_result = 0;
  char *iproc;
  int ipat1 = 0;
  int ipat2 = 0;
  int ipat3 = 0;
  int ipat4 = 0;
  char ip[16];
  strcpy(ip, ipconvertint);
  iproc = strtok(ip, ".");
  for (int i = 0; i < 4; i++) {
    switch (i) {
    case 0: {
      ipat1 = atoi(iproc);
      break;
    }
    case 1: {
      ipat2 = atoi(iproc);
      break;
    }
    case 2: {
      ipat3 = atoi(iproc);
      break;
    }
    case 3: {
      ipat4 = atoi(iproc);
      break;
    }
    default: {
      printf("Somebody misplaced an int\n");
      break;
    }
    }
    iproc = strtok(NULL, ".");
  }
  final_result = ((ipat1 * pow(2, 24)) + (ipat2 * pow(2, 16)) +
                  (ipat3 * pow(2, 8)) + ipat4 * 1);
  return final_result;
}


x86 assembly (clang, -O0):
<ip2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x40(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    1248 <ip2int+0xf8>
mov    -0x44(%rbp),%eax
mov    %rax,-0x50(%rbp)
sub    $0x3,%rax
ja     121a <ip2int+0xca>
mov    -0x50(%rbp),%rax
lea    0xe33(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1226 <ip2int+0xd6>
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    1226 <ip2int+0xd6>
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    1226 <ip2int+0xd6>
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    1226 <ip2int+0xd6>
lea    0xdf1(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xddf(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11a7 <ip2int+0x57>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    $0x2,%edi
mov    $0x18,%esi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    $0x2,%edi
mov    $0x10,%esi
call   1050 <pow@plt>
mov    -0x60(%rbp),%ecx
mov    %eax,%edx
mov    -0x5c(%rbp),%eax
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    $0x2,%edi
mov    $0x8,%esi
call   1050 <pow@plt>
mov    -0x58(%rbp),%ecx
mov    %eax,%edx
mov    -0x54(%rbp),%eax
imul   %edx,%ecx
add    %ecx,%eax
mov    -0x28(%rbp),%ecx
shl    $0x0,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip2int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
lea    0xe9d(%rip),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <strtok@plt>
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <strtok@plt>
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,%r15d
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <strtok@plt>
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,%r12d
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <strtok@plt>
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,%r13d
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <strtok@plt>
mov    $0x2,%edi
mov    $0x18,%esi
call   1040 <pow@plt>
mov    %eax,%ebx
imul   %r14d,%ebx
mov    $0x2,%edi
mov    $0x10,%esi
call   1040 <pow@plt>
mov    %eax,%ebp
imul   %r15d,%ebp
mov    $0x2,%edi
mov    $0x8,%esi
call   1040 <pow@plt>
imul   %r12d,%eax
add    %r13d,%ebx
add    %ebp,%ebx
add    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [27 x i8] c"Somebody misplaced an int\0A\00"
define i32 @ip2int(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [16 x i8]
%10 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%12 = load i8*, i8** %2
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%15 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %4
store i32 0, i32* %10
br label %16
16: ; preds = %37, %1
%17 = load i32, i32* %10
%18 = icmp slt i32 %17, 4
br i1 %18, label %19, label %40
19: ; preds = %16
%20 = load i32, i32* %10
switch i32 %20, label %33 [
i32 0, label %21
i32 1, label %24
i32 2, label %27
i32 3, label %30
]
21: ; preds = %19
%22 = load i8*, i8** %4
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %5
br label %35
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %6
br label %35
27: ; preds = %19
%28 = load i8*, i8** %4
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %7
br label %35
30: ; preds = %19
%31 = load i8*, i8** %4
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %8
br label %35
33: ; preds = %19
%34 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %30, %27, %24, %21
%36 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %36, i8** %4
br label %37
37: ; preds = %35
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %16
40: ; preds = %16
%41 = load i32, i32* %5
%42 = call i32 @pow(i32 2, i32 24)
%43 = mul nsw i32 %41, %42
%44 = load i32, i32* %6
%45 = call i32 @pow(i32 2, i32 16)
%46 = mul nsw i32 %44, %45
%47 = add nsw i32 %43, %46
%48 = load i32, i32* %7
%49 = call i32 @pow(i32 2, i32 8)
%50 = mul nsw i32 %48, %49
%51 = add nsw i32 %47, %50
%52 = load i32, i32* %8
%53 = mul nsw i32 %52, 1
%54 = add nsw i32 %51, %53
store i32 %54, i32* %3
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32 @ip2int(i8* %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* %0)
%5 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @atoi(i8* %5)
%7 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @atoi(i8* %7)
%9 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @atoi(i8* %9)
%11 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @atoi(i8* %11)
%13 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @pow(i32 2, i32 24)
%15 = mul nsw i32 %14, %6
%16 = call i32 @pow(i32 2, i32 16)
%17 = mul nsw i32 %16, %8
%18 = call i32 @pow(i32 2, i32 8)
%19 = mul nsw i32 %18, %10
%20 = add i32 %15, %12
%21 = add i32 %20, %17
%22 = add i32 %21, %19
ret i32 %22
}