#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__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serveraddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
scalar_t__ orig_connect(int, struct sockaddr_in *, int);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
short getRule(char *report) {
  int sockfd, n;
  struct sockaddr_in serveraddr;
  struct hostent *server;
  char buf[64];
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    return -1;
  }
  server = gethostbyname("127.0.0.1");
  if (server == NULL) {
    return -1;
  }
  bzero((char *)&serveraddr, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serveraddr.sin_addr.s_addr,
        server->h_length);
  serveraddr.sin_port = htons(25252);
  if (orig_connect(sockfd, &serveraddr, sizeof(serveraddr)) < 0) {
    return -1;
  }
  n = write(sockfd, report, strlen(report));
  if (n < 0) {
    return -1;
  }
  bzero(buf, 64);
  n = read(sockfd, buf, 64);
  close(sockfd);
  if (n < 0) {
    return -1;
  }
  if (!strcmp(buf, "true\n")) {
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<getRule>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11f0 <getRule+0x40>
movw   $0xffff,-0x2(%rbp)
jmp    1324 <getRule+0x174>
lea    0xe09(%rip),%rdi
call   1090 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1216 <getRule+0x66>
movw   $0xffff,-0x2(%rbp)
jmp    1324 <getRule+0x174>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bcopy@plt>
mov    $0x62a4,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <orig_connect@plt>
cmp    $0x0,%rax
jge    127e <getRule+0xce>
movw   $0xffff,-0x2(%rbp)
jmp    1324 <getRule+0x174>
mov    -0x14(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12bb <getRule+0x10b>
movw   $0xffff,-0x2(%rbp)
jmp    1324 <getRule+0x174>
lea    -0x70(%rbp),%rdi
mov    $0x40,%esi
call   10c0 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x40,%edx
call   1070 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x18(%rbp)
jge    12fa <getRule+0x14a>
movw   $0xffff,-0x2(%rbp)
jmp    1324 <getRule+0x174>
lea    -0x70(%rbp),%rdi
lea    0xd05(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    131e <getRule+0x16e>
movw   $0x0,-0x2(%rbp)
jmp    1324 <getRule+0x174>
movw   $0xffff,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRule>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r14
mov    0x2e30(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    $0xffff,%r15w
test   %eax,%eax
js     129f <getRule+0xff>
mov    %eax,%ebp
lea    0xe1e(%rip),%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     129f <getRule+0xff>
mov    %rax,%rbx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rsi
lea    0x4(%rsp),%rdi
mov    (%rbx),%edx
call   10a0 <memmove@plt>
mov    $0x62a4,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   1090 <orig_connect@plt>
test   %rax,%rax
js     129f <getRule+0xff>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
js     129f <getRule+0xff>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   10b0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1070 <read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1060 <close@plt>
test   %ebx,%ebx
js     129f <getRule+0xff>
mov    $0x65757274,%eax
xor    0x10(%rsp),%eax
movzwl 0x14(%rsp),%ecx
xor    $0xa,%ecx
xor    %r15d,%r15d
or     %eax,%ecx
setne  %r15b
neg    %r15d
mov    %r15d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [6 x i8] c"true\0A\00"
define signext i16 @getRule(i8* %0) {
%2 = alloca i16
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.hostent*
%8 = alloca [64 x i8]
store i8* %0, i8** %3
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i16 -1, i16* %2
br label %68
15: ; preds = %1
%16 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %16, %struct.hostent** %7
%17 = load %struct.hostent*, %struct.hostent** %7
%18 = icmp eq %struct.hostent* %17, null
br i1 %18, label %19, label %20
19: ; preds = %15
store i16 -1, i16* %2
br label %68
20: ; preds = %15
%21 = bitcast %struct.sockaddr_in* %6 to i8*
%22 = call i32 @bzero(i8* %21, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %23, i32* %24
%25 = load %struct.hostent*, %struct.hostent** %7
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i32 0, i32 1
%27 = load i64, i64* %26
%28 = inttoptr i64 %27 to i8*
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
%31 = bitcast i32* %30 to i8*
%32 = load %struct.hostent*, %struct.hostent** %7
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @bcopy(i8* %28, i8* %31, i32 %34)
%36 = call i32 @htons(i32 25252)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %36, i32* %37
%38 = load i32, i32* %4
%39 = call i64 @orig_connect(i32 %38, %struct.sockaddr_in* %6, i32 12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %20
store i16 -1, i16* %2
br label %68
42: ; preds = %20
%43 = load i32, i32* %4
%44 = load i8*, i8** %3
%45 = load i8*, i8** %3
%46 = call i32 @strlen(i8* %45)
%47 = call i32 @write(i32 %43, i8* %44, i32 %46)
store i32 %47, i32* %5
%48 = load i32, i32* %5
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %42
store i16 -1, i16* %2
br label %68
51: ; preds = %42
%52 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%53 = call i32 @bzero(i8* %52, i32 64)
%54 = load i32, i32* %4
%55 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%56 = call i32 @read(i32 %54, i8* %55, i32 64)
store i32 %56, i32* %5
%57 = load i32, i32* %4
%58 = call i32 @close(i32 %57)
%59 = load i32, i32* %5
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %51
store i16 -1, i16* %2
br label %68
62: ; preds = %51
%63 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%64 = call i32 @strcmp(i8* %63, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%65 = icmp ne i32 %64, 0
br i1 %65, label %67, label %66
66: ; preds = %62
store i16 0, i16* %2
br label %68
67: ; preds = %62
store i16 -1, i16* %2
br label %68
68: ; preds = %67, %66, %61, %50, %41, %19, %14
%69 = load i16, i16* %2
ret i16 %69
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [6 x i8] c"true\0A\00"
define signext i16 @getRule(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca [64 x i8]
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %41, label %10
10: ; preds = %1
%11 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq %struct.hostent* %11, null
br i1 %12, label %41, label %13
13: ; preds = %10
%14 = call i32 @bzero(i8* %4, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 1
%18 = load i64, i64* %17
%19 = inttoptr i64 %18 to i8*
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
%21 = bitcast i32* %20 to i8*
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %11, i64 0, i32 0
%23 = load i32, i32* %22
%24 = tail call i32 @htons(i32 25252)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %24, i32* %25
%26 = call i64 @orig_connect(i32 %8, %struct.sockaddr_in* %2, i32 12)
%27 = icmp slt i64 %26, 0
br i1 %27, label %41, label %28
28: ; preds = %13
%29 = call i32 @strlen(i8* %0)
%30 = call i32 @write(i32 %8, i8* %0, i32 %29)
%31 = icmp slt i32 %30, 0
br i1 %31, label %41, label %32
32: ; preds = %28
%33 = call i32 @bzero(i8* %5, i32 64)
%34 = call i32 @read(i32 %8, i8* %5, i32 64)
%35 = call i32 @close(i32 %8)
%36 = icmp slt i32 %34, 0
br i1 %36, label %41, label %37
37: ; preds = %32
%38 = call i32 @bcmp(i8* dereferenceable(6) %5, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 6)
%39 = icmp ne i32 %38, 0
%40 = sext i1 %39 to i16
br label %41
41: ; preds = %37, %32, %28, %13, %10, %1
%42 = phi i16 [ -1, %1 ], [ -1, %10 ], [ -1, %13 ], [ -1, %28 ], [ -1, %32 ], [ %40, %37 ]
ret i16 %42
}