#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 /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int iptofin(char *ip) {
  int bip = 0;
  int fin = 0;
  int i = 0;
  int j = 0;
  char finip[3];
  fin = strlen(ip);
  printf("ip=%s...", ip);
  for (i = 11; i <= fin; i++) {
    if (j < 3)
      finip[j] = ip[i];
    j++;
  }
  printf("finip=%s...", finip);
  bip = atoi(finip);
  printf("bipip=%d\n", bip);
  return bip;
}


x86 assembly (clang, -O0):
<iptofin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xb,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11bd <iptofin+0x8d>
cmpl   $0x3,-0x18(%rbp)
jge    11a6 <iptofin+0x76>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x1b(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <iptofin+0x4d>
lea    -0x1b(%rbp),%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1b(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iptofin>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    0xebf(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0xb,%ebp
jl     1175 <iptofin+0x45>
add    $0xfffffff6,%ebp
mov    0xb(%rbx),%al
mov    %al,0x5(%rsp)
cmp    $0x1,%ebp
je     1175 <iptofin+0x45>
mov    0xc(%rbx),%al
mov    %al,0x6(%rsp)
cmp    $0x2,%ebp
je     1175 <iptofin+0x45>
mov    0xd(%rbx),%al
mov    %al,0x7(%rsp)
lea    0xe84(%rip),%rdi
lea    0x5(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
lea    0xe70(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"ip=%s...\00"
@.str.1 = [12 x i8] c"finip=%s...\00"
@.str.2 = [10 x i8] c"bipip=%d\0A\00"
define i32 @iptofin(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [3 x i8]
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %4
%10 = load i8*, i8** %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %10)
store i32 11, i32* %5
br label %12
12: ; preds = %31, %1
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = load i8*, i8** %2
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 %26
store i8 %24, i8* %27
br label %28
28: ; preds = %19, %16
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %31
31: ; preds = %28
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %12
34: ; preds = %12
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %3
%39 = load i32, i32* %3
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [9 x i8] c"ip=%s...\00"
@.str.1 = [12 x i8] c"finip=%s...\00"
@.str.2 = [10 x i8] c"bipip=%d\0A\00"
define i32 @iptofin(i8* %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = icmp slt i32 %4, 11
br i1 %6, label %21, label %7
7: ; preds = %1
%8 = add nsw i32 %4, -10
%9 = getelementptr inbounds i8, i8* %0, i64 11
%10 = load i8, i8* %9
store i8 %10, i8* %3
%11 = icmp eq i32 %8, 1
br i1 %11, label %21, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %0, i64 12
%14 = load i8, i8* %13
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 %14, i8* %15
%16 = icmp eq i32 %8, 2
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %0, i64 13
%19 = load i8, i8* %18
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
store i8 %19, i8* %20
br label %21
21: ; preds = %17, %7, %12, %1
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%23 = call i32 @atoi(i8* %3)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %23)
ret i32 %23
}