#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ asprintf(char **, char *, char *, int);
int /*<<< orphan*/ free(char *);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int isValidIpAddress(char *ipaddr) {
  struct sockaddr_in sa;
  char *test = NULL;
  asprintf(&test, "%s.%d", ipaddr, 1);
  int result = 0;
  result = inet_pton(AF_INET, test, &(sa.sin_addr));
  free(test);
  return result != 0;
}


x86 assembly (clang, -O0):
<isValidIpAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    0xead(%rip),%rsi
mov    $0x1,%ecx
call   1050 <asprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <inet_pton@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isValidIpAddress>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rdx
movq   $0x0,(%rsp)
lea    0xeb9(%rip),%rsi
mov    %rsp,%rdi
mov    $0x1,%ecx
call   1050 <asprintf@plt>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    (%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <inet_pton@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
test   %ebx,%ebx
setne  %al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@.str = [6 x i8] c"%s.%d\00"
@AF_INET = global i32 0
define i32 @isValidIpAddress(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.sockaddr_in
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %4
%6 = load i8*, i8** %2
%7 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %6, i32 1)
store i32 0, i32* %5
%8 = load i32, i32* @AF_INET
%9 = load i8*, i8** %4
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%11 = call i32 @inet_pton(i32 %8, i8* %9, i32* %10)
store i32 %11, i32* %5
%12 = load i8*, i8** %4
%13 = call i32 @free(i8* %12)
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i32
ret i32 %16
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
@.str = [6 x i8] c"%s.%d\00"
@AF_INET = global i32 0
define i32 @isValidIpAddress(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i8*
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i32 1)
%7 = load i32, i32* @AF_INET
%8 = load i8*, i8** %3
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%10 = call i32 @inet_pton(i32 %7, i8* %8, i32* %9)
%11 = load i8*, i8** %3
%12 = call i32 @free(i8* %11)
%13 = icmp ne i32 %10, 0
%14 = zext i1 %13 to i32
ret i32 %14
}