#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 /*<<< orphan*/ sscanf(char const *, char *, unsigned int *, unsigned int *,
                          unsigned int *, unsigned int *);
unsigned uInIpv4Format(const char *cIPv4, unsigned *uIPv4) {
  unsigned a = 0, b = 0, c = 0, d = 0;
  sscanf(cIPv4, "%u.%u.%u.%u", &a, &b, &c, &d);
  if (!a)
    return (0);
  if (b > 254)
    return (0);
  if (c > 254)
    return (0);
  if (d > 254)
    return (0);
  *uIPv4 = d + (c << 8) + (b << 16) + (a << 24);
  return (1);
}


x86 assembly (clang, -O0):
<uInIpv4Format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%r8
lea    -0x28(%rbp),%r9
call   1030 <sscanf@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1172 <uInIpv4Format+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <uInIpv4Format+0xd5>
cmpl   $0xfe,-0x20(%rbp)
jbe    118b <uInIpv4Format+0x7b>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <uInIpv4Format+0xd5>
cmpl   $0xfe,-0x24(%rbp)
jbe    11a4 <uInIpv4Format+0x94>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <uInIpv4Format+0xd5>
cmpl   $0xfe,-0x28(%rbp)
jbe    11bd <uInIpv4Format+0xad>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <uInIpv4Format+0xd5>
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%eax
shl    $0x8,%eax
add    %eax,%ecx
mov    -0x20(%rbp),%eax
shl    $0x10,%eax
add    %eax,%ecx
mov    -0x1c(%rbp),%eax
shl    $0x18,%eax
add    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uInIpv4Format>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0xec2(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rsp,%r9
call   1030 <sscanf@plt>
mov    0xc(%rsp),%ecx
xor    %eax,%eax
test   %ecx,%ecx
je     1198 <uInIpv4Format+0x88>
mov    0x8(%rsp),%edx
cmp    $0xfe,%edx
ja     1198 <uInIpv4Format+0x88>
mov    0x4(%rsp),%esi
cmp    $0xfe,%esi
ja     1198 <uInIpv4Format+0x88>
mov    (%rsp),%edi
cmp    $0xfe,%edi
ja     1198 <uInIpv4Format+0x88>
shl    $0x8,%esi
shl    $0x10,%edx
shl    $0x18,%ecx
add    %edx,%ecx
add    %esi,%ecx
add    %edi,%ecx
mov    %ecx,(%rbx)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i32 @uInIpv4Format(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
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%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 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 0, i32* %3
br label %39
15: ; preds = %2
%16 = load i32, i32* %7
%17 = icmp ugt i32 %16, 254
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 0, i32* %3
br label %39
19: ; preds = %15
%20 = load i32, i32* %8
%21 = icmp ugt i32 %20, 254
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 0, i32* %3
br label %39
23: ; preds = %19
%24 = load i32, i32* %9
%25 = icmp ugt i32 %24, 254
br i1 %25, label %26, label %27
26: ; preds = %23
store i32 0, i32* %3
br label %39
27: ; preds = %23
%28 = load i32, i32* %9
%29 = load i32, i32* %8
%30 = shl i32 %29, 8
%31 = add i32 %28, %30
%32 = load i32, i32* %7
%33 = shl i32 %32, 16
%34 = add i32 %31, %33
%35 = load i32, i32* %6
%36 = shl i32 %35, 24
%37 = add i32 %34, %36
%38 = load i32*, i32** %5
store i32 %37, i32* %38
store i32 1, i32* %3
br label %39
39: ; preds = %27, %26, %22, %18, %14
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [12 x i8] c"%u.%u.%u.%u\00"
define i32 @uInIpv4Format(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*
store i32 0, i32* %3
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%10 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%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 = load i32, i32* %3
%13 = icmp eq i32 %12, 0
br i1 %13, label %30, label %14
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp ugt i32 %15, 254
br i1 %16, label %30, label %17
17: ; preds = %14
%18 = load i32, i32* %5
%19 = icmp ugt i32 %18, 254
br i1 %19, label %30, label %20
20: ; preds = %17
%21 = load i32, i32* %6
%22 = icmp ugt i32 %21, 254
br i1 %22, label %30, label %23
23: ; preds = %20
%24 = shl nuw nsw i32 %18, 8
%25 = shl nuw nsw i32 %15, 16
%26 = shl i32 %12, 24
%27 = add nuw i32 %25, %26
%28 = add nuw i32 %27, %24
%29 = add nuw i32 %28, %21
store i32 %29, i32* %1
br label %30
30: ; preds = %20, %17, %14, %2, %23
%31 = phi i32 [ 1, %23 ], [ 0, %2 ], [ 0, %14 ], [ 0, %17 ], [ 0, %20 ]
ret i32 %31
}