#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 inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
int isValidIpAddress(char *ipAddress) {
  char tmp[100];
  strncpy(tmp, ipAddress, 100);
  char *pch = strtok(tmp, "-");
  struct sockaddr_in sa;
  int result;
  if (pch != NULL) {
    result = inet_pton(AF_INET, pch, &(sa.sin_addr));
    if (result != 0) {
      return 1;
    }
    pch = strtok(NULL, "-");
  }
  return 0;
}


x86 assembly (clang, -O0):
<isValidIpAddress>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x64,%edx
call   1030 <strncpy@plt>
lea    -0x80(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     11c8 <isValidIpAddress+0x98>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    -0x88(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1040 <inet_pton@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
je     11b1 <isValidIpAddress+0x81>
movl   $0x1,-0x4(%rbp)
jmp    11cf <isValidIpAddress+0x9f>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe44(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x88(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isValidIpAddress>:
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
lea    0xeac(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     1192 <isValidIpAddress+0x62>
mov    0x2e80(%rip),%rcx
mov    (%rcx),%edi
lea    0x8(%rsp),%rdx
mov    %rax,%rsi
call   1040 <inet_pton@plt>
mov    $0x1,%ebx
test   %eax,%eax
jne    1194 <isValidIpAddress+0x64>
lea    0xe79(%rip),%rsi
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <strtok@plt>
jmp    1194 <isValidIpAddress+0x64>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@.str = [2 x i8] c"-\00"
@AF_INET = global i32 0
define i32 @isValidIpAddress(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [100 x i8]
%5 = alloca i8*
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
store i8* %0, i8** %3
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @strncpy(i8* %8, i8* %9, i32 100)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%12 = call i8* @strtok(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %25
15: ; preds = %1
%16 = load i32, i32* @AF_INET
%17 = load i8*, i8** %5
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%19 = call i32 @inet_pton(i32 %16, i8* %17, i32* %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 1, i32* %2
br label %26
23: ; preds = %15
%24 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %24, i8** %5
br label %25
25: ; preds = %23, %1
store i32 0, i32* %2
br label %26
26: ; preds = %25, %22
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
@.str = [2 x i8] c"-\00"
@AF_INET = global i32 0
define i32 @isValidIpAddress(i8* %0) {
%2 = alloca [100 x i8]
%3 = alloca %struct.sockaddr_in
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = call i32 @strncpy(i8* %4, i8* %0, i32 100)
%6 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = icmp eq i8* %6, null
br i1 %8, label %16, label %9
9: ; preds = %1
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%12 = call i32 @inet_pton(i32 %10, i8* %6, i32* %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %1, %14, %9
%17 = phi i32 [ 1, %9 ], [ 0, %14 ], [ 0, %1 ]
ret i32 %17
}