#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ inet_addr(char *);
char *str_dup(char const *);
char *strchr(char *, char);
int ClientAddrOK(struct sockaddr_in *saPtr, const char *clientList) {
  int result = (0);
  char *clientListCopy, *cur, *next;
  if (clientList == NULL || *clientList == '\0') {
    return (1);
  }
  clientListCopy = str_dup(clientList);
  for (cur = clientListCopy; cur != NULL; cur = next) {
    next = strchr(cur, ',');
    if (next != NULL) {
      *next++ = '\0';
    }
    if (inet_addr(cur) == saPtr->sin_addr.s_addr) {
      result = (1);
      break;
    }
  }
  free(clientListCopy);
  return result;
}


x86 assembly (clang, -O0):
<ClientAddrOK>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1172 <ClientAddrOK+0x32>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117e <ClientAddrOK+0x3e>
movl   $0x1,-0x4(%rbp)
jmp    1210 <ClientAddrOK+0xd0>
mov    -0x18(%rbp),%rdi
call   1060 <str_dup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1201 <ClientAddrOK+0xc1>
mov    -0x30(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11cd <ClientAddrOK+0x8d>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
call   1050 <inet_addr@plt>
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    11ef <ClientAddrOK+0xaf>
movl   $0x1,-0x1c(%rbp)
jmp    1201 <ClientAddrOK+0xc1>
jmp    11f4 <ClientAddrOK+0xb4>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1193 <ClientAddrOK+0x53>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ClientAddrOK>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x1,%r14d
test   %rsi,%rsi
je     11b5 <ClientAddrOK+0x75>
cmpb   $0x0,(%rsi)
je     11b5 <ClientAddrOK+0x75>
mov    %rdi,%r12
mov    %rsi,%rdi
call   1060 <str_dup@plt>
mov    %rax,%r15
xor    %r14d,%r14d
mov    %rax,%rbx
jmp    118b <ClientAddrOK+0x4b>
nop
mov    %rax,%r13
add    $0x1,%r13
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1050 <inet_addr@plt>
mov    %r13,%rbx
cmp    (%r12),%rax
je     11a7 <ClientAddrOK+0x67>
test   %rbx,%rbx
je     11ad <ClientAddrOK+0x6d>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1170 <ClientAddrOK+0x30>
xor    %r13d,%r13d
jmp    117a <ClientAddrOK+0x3a>
mov    $0x1,%r14d
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
define i32 @ClientAddrOK(%struct.sockaddr_in* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12, %2
store i32 1, i32* %3
br label %49
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = call i8* @str_dup(i8* %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
store i8* %21, i8** %8
br label %22
22: ; preds = %43, %18
%23 = load i8*, i8** %8
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %45
25: ; preds = %22
%26 = load i8*, i8** %8
%27 = call i8* @strchr(i8* %26, i8 signext 44)
store i8* %27, i8** %9
%28 = load i8*, i8** %9
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i8*, i8** %9
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %9
store i8 0, i8* %31
br label %33
33: ; preds = %30, %25
%34 = load i8*, i8** %8
%35 = call i64 @inet_addr(i8* %34)
%36 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %36, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
%39 = load i64, i64* %38
%40 = icmp eq i64 %35, %39
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 1, i32* %6
br label %45
42: ; preds = %33
br label %43
43: ; preds = %42
%44 = load i8*, i8** %9
store i8* %44, i8** %8
br label %22
45: ; preds = %41, %22
%46 = load i8*, i8** %7
%47 = call i32 @free(i8* %46)
%48 = load i32, i32* %6
store i32 %48, i32* %3
br label %49
49: ; preds = %45, %17
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
define i32 @ClientAddrOK(%struct.sockaddr_in* nocapture %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %26, label %4
4: ; preds = %2
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %26, label %7
7: ; preds = %4
%8 = tail call i8* @str_dup(i8* %1)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0, i32 0
br label %10
10: ; preds = %18, %7
%11 = phi i8* [ %8, %7 ], [ %19, %18 ]
%12 = icmp eq i8* %11, null
br i1 %12, label %23, label %13
13: ; preds = %10
%14 = tail call i8* @strchr(i8* %11, i8 signext 44)
%15 = icmp eq i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %14, i64 1
store i8 0, i8* %14
br label %18
18: ; preds = %16, %13
%19 = phi i8* [ %17, %16 ], [ null, %13 ]
%20 = tail call i64 @inet_addr(i8* %11)
%21 = load i64, i64* %9
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %10
23: ; preds = %18, %10
%24 = phi i32 [ 0, %10 ], [ 1, %18 ]
%25 = tail call i32 @free(i8* %8)
br label %26
26: ; preds = %2, %4, %23
%27 = phi i32 [ %24, %23 ], [ 1, %4 ], [ 1, %2 ]
ret i32 %27
}