#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 *, unsigned int *, unsigned int *, unsigned int *,
           unsigned int *);
unsigned int ip_to_uint(const char *ip) {
  unsigned int IP[4];
  if ((sscanf(ip, "%u.%u.%u.%u", &IP[0], &IP[1], &IP[2], &IP[3]) == 4) &&
      ((IP[0] < 256) && (IP[1] < 256) && (IP[2] < 256) && (IP[3] < 256)))
    return ((IP[0] << 24) | (IP[1] << 16) | (IP[2] << 8) | IP[3]);
  else
    return 0;
}


x86 assembly (clang, -O0):
<ip_to_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    -0x20(%rbp),%rcx
add    $0x4,%rcx
lea    -0x20(%rbp),%r8
add    $0x8,%r8
lea    -0x20(%rbp),%r9
add    $0xc,%r9
lea    0xebd(%rip),%rsi
call   1030 <sscanf@plt>
cmp    $0x4,%eax
jne    11a6 <ip_to_uint+0x96>
cmpl   $0x100,-0x20(%rbp)
jae    11a6 <ip_to_uint+0x96>
cmpl   $0x100,-0x1c(%rbp)
jae    11a6 <ip_to_uint+0x96>
cmpl   $0x100,-0x18(%rbp)
jae    11a6 <ip_to_uint+0x96>
cmpl   $0x100,-0x14(%rbp)
jae    11a6 <ip_to_uint+0x96>
mov    -0x20(%rbp),%eax
shl    $0x18,%eax
mov    -0x1c(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <ip_to_uint+0x9d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_to_uint>:
sub    $0x18,%rsp
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0xed6(%rip),%rsi
mov    %rsp,%rdx
call   1030 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x4,%ecx
jne    117b <ip_to_uint+0x6b>
mov    (%rsp),%ecx
cmp    $0xff,%ecx
ja     117b <ip_to_uint+0x6b>
mov    0x4(%rsp),%edx
cmp    $0xff,%edx
ja     117b <ip_to_uint+0x6b>
mov    0x8(%rsp),%esi
cmp    $0xff,%esi
ja     117b <ip_to_uint+0x6b>
mov    0xc(%rsp),%edi
cmp    $0xff,%edi
ja     117b <ip_to_uint+0x6b>
shl    $0x18,%ecx
shl    $0x10,%edx
or     %ecx,%edx
shl    $0x8,%esi
or     %edx,%esi
or     %edi,%esi
mov    %esi,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i32 @ip_to_uint(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i32]
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%10 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8, i32* %9)
%11 = icmp eq i32 %10, 4
br i1 %11, label %12, label %43
12: ; preds = %1
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%14 = load i32, i32* %13
%15 = icmp ult i32 %14, 256
br i1 %15, label %16, label %43
16: ; preds = %12
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%18 = load i32, i32* %17
%19 = icmp ult i32 %18, 256
br i1 %19, label %20, label %43
20: ; preds = %16
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%22 = load i32, i32* %21
%23 = icmp ult i32 %22, 256
br i1 %23, label %24, label %43
24: ; preds = %20
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%26 = load i32, i32* %25
%27 = icmp ult i32 %26, 256
br i1 %27, label %28, label %43
28: ; preds = %24
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%30 = load i32, i32* %29
%31 = shl i32 %30, 24
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%33 = load i32, i32* %32
%34 = shl i32 %33, 16
%35 = or i32 %31, %34
%36 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%37 = load i32, i32* %36
%38 = shl i32 %37, 8
%39 = or i32 %35, %38
%40 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%41 = load i32, i32* %40
%42 = or i32 %39, %41
store i32 %42, i32* %2
br label %44
43: ; preds = %24, %20, %16, %12, %1
store i32 0, i32* %2
br label %44
44: ; preds = %43, %28
%45 = load i32, i32* %2
ret i32 %45
}

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