#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int sscanf(char *, char *, int *, int *, int *, int *);
int /*<<< orphan*/ stderr;
int parse_ip(char *src, unsigned int *ip) {
  int count, i;
  int buf[4];
  count = sscanf(src, "%d.%d.%d.%d", &buf[0], &buf[1], &buf[2], &buf[3]);
  if (count != 4) {
    fprintf(stderr, "Illegall IP address (should be %%d.%%d.%%d.%%d)\n");
    exit(-1);
  }
  *ip = (((buf[0] & 0xFF) << 24) | ((buf[1] & 0xFF) << 16) |
         ((buf[2] & 0xFF) << 8) | ((buf[3] & 0xFF) << 0));
  return 0;
}


x86 assembly (clang, -O0):
<parse_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
add    $0x4,%rcx
lea    -0x30(%rbp),%r8
add    $0x8,%r8
lea    -0x30(%rbp),%r9
add    $0xc,%r9
lea    0xe99(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
je     1198 <parse_ip+0x68>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x30(%rbp),%ecx
and    $0xff,%ecx
shl    $0x18,%ecx
mov    -0x2c(%rbp),%eax
and    $0xff,%eax
shl    $0x10,%eax
or     %eax,%ecx
mov    -0x28(%rbp),%eax
and    $0xff,%eax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x24(%rbp),%eax
and    $0xff,%eax
shl    $0x0,%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ip>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
lea    0xeb2(%rip),%rsi
mov    %rsp,%rdx
call   1040 <sscanf@plt>
cmp    $0x4,%eax
jne    118a <parse_ip+0x5a>
mov    (%rsp),%eax
mov    0x4(%rsp),%ecx
shl    $0x18,%eax
movzbl %cl,%ecx
shl    $0x10,%ecx
or     %eax,%ecx
mov    0x8(%rsp),%eax
shl    $0x8,%eax
movzwl %ax,%eax
or     %ecx,%eax
movzbl 0xc(%rsp),%ecx
or     %eax,%ecx
mov    %ecx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
@stderr = global i32 0
@.str.1 = [49 x i8] c"Illegall IP address (should be %%d.%%d.%%d.%%d)\0A\00"
define i32 @parse_ip(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [4 x i32]
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = load i8*, i8** %3
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 0
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 1
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 2
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 3
%13 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %9, i32* %10, i32* %11, i32* %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 0
%22 = load i32, i32* %21
%23 = and i32 %22, 255
%24 = shl i32 %23, 24
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 1
%26 = load i32, i32* %25
%27 = and i32 %26, 255
%28 = shl i32 %27, 16
%29 = or i32 %24, %28
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 2
%31 = load i32, i32* %30
%32 = and i32 %31, 255
%33 = shl i32 %32, 8
%34 = or i32 %29, %33
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 3
%36 = load i32, i32* %35
%37 = and i32 %36, 255
%38 = shl i32 %37, 0
%39 = or i32 %34, %38
%40 = load i32*, i32** %4
store i32 %39, i32* %40
ret i32 0
}

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