#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 sscanf(char const *, char *, int *, int *, int *, int *);
int ipaddr_to_int(const char *stringIP, unsigned int *ip) {
  int a, b, c, d;
  if (4 != sscanf(stringIP, "%d.%d.%d.%d", &a, &b, &c, &d)) {
    return -1;
  }
  *ip =
      ((a & 0xFF) << 24) + ((b & 0xFF) << 16) + ((c & 0xFF) << 8) + (d & 0xFF);
  return 0;
}


x86 assembly (clang, -O0):
<ipaddr_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed5(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
lea    -0x28(%rbp),%r9
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0x4,%eax
cmp    %ecx,%eax
je     115b <ipaddr_to_int+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <ipaddr_to_int+0x88>
mov    -0x1c(%rbp),%ecx
and    $0xff,%ecx
shl    $0x18,%ecx
mov    -0x20(%rbp),%eax
and    $0xff,%eax
shl    $0x10,%eax
add    %eax,%ecx
mov    -0x24(%rbp),%eax
and    $0xff,%eax
shl    $0x8,%eax
add    %eax,%ecx
mov    -0x28(%rbp),%eax
and    $0xff,%eax
add    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipaddr_to_int>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xee1(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rsp,%r9
call   1030 <sscanf@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x4,%ecx
jne    116b <ipaddr_to_int+0x5b>
mov    0xc(%rsp),%eax
shl    $0x18,%eax
mov    0x8(%rsp),%ecx
movzbl %cl,%ecx
shl    $0x10,%ecx
or     %eax,%ecx
mov    0x4(%rsp),%eax
shl    $0x8,%eax
movzwl %ax,%eax
or     %ecx,%eax
movzbl (%rsp),%ecx
or     %eax,%ecx
mov    %ecx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @ipaddr_to_int(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%10 = load i8*, i8** %4
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9)
%12 = icmp ne i32 4, %11
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %30
14: ; preds = %2
%15 = load i32, i32* %6
%16 = and i32 %15, 255
%17 = shl i32 %16, 24
%18 = load i32, i32* %7
%19 = and i32 %18, 255
%20 = shl i32 %19, 16
%21 = add nsw i32 %17, %20
%22 = load i32, i32* %8
%23 = and i32 %22, 255
%24 = shl i32 %23, 8
%25 = add nsw i32 %21, %24
%26 = load i32, i32* %9
%27 = and i32 %26, 255
%28 = add nsw i32 %25, %27
%29 = load i32*, i32** %5
store i32 %28, i32* %29
store i32 0, i32* %3
br label %30
30: ; preds = %14, %13
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @ipaddr_to_int(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6)
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %27
13: ; preds = %2
%14 = load i32, i32* %3
%15 = shl i32 %14, 24
%16 = load i32, i32* %4
%17 = shl i32 %16, 16
%18 = and i32 %17, 16711680
%19 = or i32 %18, %15
%20 = load i32, i32* %5
%21 = shl i32 %20, 8
%22 = and i32 %21, 65280
%23 = or i32 %19, %22
%24 = load i32, i32* %6
%25 = and i32 %24, 255
%26 = or i32 %23, %25
store i32 %26, i32* %1
br label %27
27: ; preds = %2, %13
%28 = phi i32 [ 0, %13 ], [ -1, %2 ]
ret i32 %28
}