#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 */
struct in_addr {
  int dummy;
};

/* Variables and functions */
int inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ log_Printf(int, char *, int, char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int do_inet_aton(const char *start, const char *end, struct in_addr *ip) {
  char ipstr[16];
  if (end - start > 15) {
    log_Printf((23), "%.*s: Invalid IP address\n", (int)(end - start), start);
    return 0;
  }
  strncpy(ipstr, start, end - start);
  ipstr[end - start] = '\0';
  return inet_aton(ipstr, ip);
}


x86 assembly (clang, -O0):
<do_inet_aton>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    $0xf,%rax
jle    1187 <do_inet_aton+0x57>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x17,%edi
lea    0xe8a(%rip),%rsi
call   1030 <log_Printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <do_inet_aton+0x91>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <inet_aton@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_inet_aton>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%rcx
sub    %rdi,%rbx
cmp    $0x10,%rbx
jl     115f <do_inet_aton+0x2f>
lea    0xeb1(%rip),%rsi
mov    $0x17,%edi
mov    %ebx,%edx
call   1030 <log_Printf@plt>
xor    %eax,%eax
jmp    1181 <do_inet_aton+0x51>
mov    %rdx,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rcx,%rsi
mov    %ebx,%edx
call   1040 <strncpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <inet_aton@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@.str = [26 x i8] c"%.*s: Invalid IP address\0A\00"
define i32 @do_inet_aton(i8* %0, i8* %1, %struct.in_addr* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.in_addr*
%8 = alloca [16 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store %struct.in_addr* %2, %struct.in_addr** %7
%9 = load i8*, i8** %6
%10 = load i8*, i8** %5
%11 = ptrtoint i8* %9 to i64
%12 = ptrtoint i8* %10 to i64
%13 = sub i64 %11, %12
%14 = icmp sgt i64 %13, 15
br i1 %14, label %15, label %24
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = load i8*, i8** %5
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = load i8*, i8** %5
%23 = call i32 @log_Printf(i32 23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %21, i8* %22)
store i32 0, i32* %4
br label %43
24: ; preds = %3
%25 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = load i8*, i8** %6
%28 = load i8*, i8** %5
%29 = ptrtoint i8* %27 to i64
%30 = ptrtoint i8* %28 to i64
%31 = sub i64 %29, %30
%32 = trunc i64 %31 to i32
%33 = call i32 @strncpy(i8* %25, i8* %26, i32 %32)
%34 = load i8*, i8** %6
%35 = load i8*, i8** %5
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %38
store i8 0, i8* %39
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%41 = load %struct.in_addr*, %struct.in_addr** %7
%42 = call i32 @inet_aton(i8* %40, %struct.in_addr* %41)
store i32 %42, i32* %4
br label %43
43: ; preds = %24, %15
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [26 x i8] c"%.*s: Invalid IP address\0A\00"
define i32 @do_inet_aton(i8* %0, i8* %1, %struct.in_addr* %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = ptrtoint i8* %1 to i64
%7 = ptrtoint i8* %0 to i64
%8 = sub i64 %6, %7
%9 = icmp sgt i64 %8, 15
%10 = trunc i64 %8 to i32
br i1 %9, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @log_Printf(i32 23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %0)
br label %17
13: ; preds = %3
%14 = call i32 @strncpy(i8* %5, i8* %0, i32 %10)
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %8
store i8 0, i8* %15
%16 = call i32 @inet_aton(i8* %5, %struct.in_addr* %2)
br label %17
17: ; preds = %13, %11
%18 = phi i32 [ 0, %11 ], [ %16, %13 ]
ret i32 %18
}