#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int create_socket(char *, int);
int /*<<< orphan*/ readline(int, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ writeline(int, char *);
int replica_exists(char *ip, char *replica_name) {
  int connfd = create_socket(ip, 2000);
  char result[10];
  if (connfd < 0) {
    return 0;
  }
  writeline(connfd, "CHECK");
  writeline(connfd, replica_name);
  readline(connfd, result);
  close(connfd);
  return (strcmp(result, "YES") == 0);
}


x86 assembly (clang, -O0):
<replica_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x7d0,%esi
call   1060 <create_socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1187 <replica_exists+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <replica_exists+0x85>
mov    -0x1c(%rbp),%edi
lea    0xe6f(%rip),%rsi
call   1070 <writeline@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <writeline@plt>
mov    -0x1c(%rbp),%edi
lea    -0x26(%rbp),%rsi
call   1030 <readline@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
lea    -0x26(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replica_exists>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    $0x7d0,%esi
call   1060 <create_socket@plt>
test   %eax,%eax
js     11b4 <replica_exists+0x64>
mov    %eax,%ebx
lea    0xe8f(%rip),%rsi
mov    %eax,%edi
call   1070 <writeline@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <writeline@plt>
lea    0xe(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <readline@plt>
mov    %ebx,%edi
call   1040 <close@plt>
lea    0xe67(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    11b6 <replica_exists+0x66>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"CHECK\00"
@.str.1 = [4 x i8] c"YES\00"
define i32 @replica_exists(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [10 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @create_socket(i8* %8, i32 2000)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %28
13: ; preds = %2
%14 = load i32, i32* %6
%15 = call i32 @writeline(i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %6
%17 = load i8*, i8** %5
%18 = call i32 @writeline(i32 %16, i8* %17)
%19 = load i32, i32* %6
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%21 = call i32 @readline(i32 %19, i8* %20)
%22 = load i32, i32* %6
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
store i32 %27, i32* %3
br label %28
28: ; preds = %13, %12
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [6 x i8] c"CHECK\00"
@.str.1 = [4 x i8] c"YES\00"
define i32 @replica_exists(i8* %0, i8* %1) {
%3 = alloca [10 x i8]
%4 = tail call i32 @create_socket(i8* %0, i32 2000)
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = icmp slt i32 %4, 0
br i1 %6, label %15, label %7
7: ; preds = %2
%8 = tail call i32 @writeline(i32 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @writeline(i32 %4, i8* %1)
%10 = call i32 @readline(i32 %4, i8* %5)
%11 = call i32 @close(i32 %4)
%12 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %2, %7
%16 = phi i32 [ %14, %7 ], [ 0, %2 ]
ret i32 %16
}