#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 */
typedef int /*<<< orphan*/ ice_isA_packet;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int sock_connect(char *, char const *);
int sock_read(int, unsigned char *, int);
int sock_write(int, unsigned char const *, int);
int /*<<< orphan*/ stderr;
int murmur_connect(const char *port) {
  int murmfd;
  unsigned char read_buffer[512];
  const unsigned char ice_isA_packet[] = {
      0x49, 0x63, 0x65, 0x50, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x38, 0x00,
      0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x4d, 0x65, 0x74, 0x61, 0x00,
      0x00, 0x07, 0x69, 0x63, 0x65, 0x5f, 0x69, 0x73, 0x41, 0x01, 0x00, 0x15,
      0x00, 0x00, 0x00, 0x01, 0x00, 0x0e, 0x3a, 0x3a, 0x4d, 0x75, 0x72, 0x6d,
      0x75, 0x72, 0x3a, 0x3a, 0x4d, 0x65, 0x74, 0x61};
  murmfd = sock_connect("127.0.0.1", port);
  if (murmfd < 0)
    return -1;
  if (sock_read(murmfd, read_buffer, 512) != 14) {
    fprintf(stderr, "Error: Failed to receive validate_packet\n");
    goto cleanup;
  }
  if (sock_write(murmfd, ice_isA_packet, sizeof(ice_isA_packet)) !=
      sizeof(ice_isA_packet)) {
    fprintf(stderr, "Error: Failed to send ice_isA_packet\n");
    goto cleanup;
  }
  if (sock_read(murmfd, read_buffer, 512) != 26) {
    fprintf(stderr, "Error: Failed to receive ice_isA_packet success reply\n");
    goto cleanup;
  }
  return murmfd;
cleanup:
  close(murmfd);
  return -1;
}


x86 assembly (clang, -O0):
<murmur_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x260(%rbp),%rdi
lea    0xe83(%rip),%rsi
mov    $0x38,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rsi
lea    0xea6(%rip),%rdi
call   1080 <sock_connect@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b0 <murmur_connect+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    1272 <murmur_connect+0x112>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1070 <sock_read@plt>
cmp    $0xe,%eax
je     11e7 <murmur_connect+0x87>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1263 <murmur_connect+0x103>
mov    -0x14(%rbp),%edi
lea    -0x260(%rbp),%rsi
mov    $0x38,%edx
call   1060 <sock_write@plt>
cltq
cmp    $0x38,%rax
je     1221 <murmur_connect+0xc1>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1263 <murmur_connect+0x103>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1070 <sock_read@plt>
cmp    $0x1a,%eax
je     1258 <murmur_connect+0xf8>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1263 <murmur_connect+0x103>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1272 <murmur_connect+0x112>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<murmur_connect>:
push   %rbp
push   %rbx
sub    $0x248,%rsp
mov    %rdi,%rsi
movaps 0xebd(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xea1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe85(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x6174654d3a3a7275,%rax
65 74 61
mov    %rax,0x30(%rsp)
lea    0xea3(%rip),%rdi
call   1070 <sock_connect@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1217 <murmur_connect+0xc7>
mov    %eax,%ebp
lea    0x40(%rsp),%rsi
mov    %eax,%edi
mov    $0x200,%edx
call   1060 <sock_read@plt>
cmp    $0xe,%eax
jne    11e9 <murmur_connect+0x99>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x38,%edx
call   1050 <sock_write@plt>
cmp    $0x38,%eax
jne    11f2 <murmur_connect+0xa2>
lea    0x40(%rsp),%rsi
mov    %ebp,%edi
mov    $0x200,%edx
call   1060 <sock_read@plt>
cmp    $0x1a,%eax
jne    11fb <murmur_connect+0xab>
mov    %ebp,%ebx
jmp    1217 <murmur_connect+0xc7>
lea    0xe52(%rip),%rsi
jmp    1202 <murmur_connect+0xb2>
lea    0xe73(%rip),%rsi
jmp    1202 <murmur_connect+0xb2>
lea    0xe90(%rip),%rsi
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1040 <fprintf@plt>
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
add    $0x248,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.murmur_connect.ice_isA_packet = [56 x i8] c"IceP\01\00\01\00\00\008\00\00\00\01\00\00\00\04Meta\00\00\07ice_isA\01\00\15\00\00\00\01\00\0E::Murmur::Meta"
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"Error: Failed to receive validate_packet\0A\00"
@.str.2 = [38 x i8] c"Error: Failed to send ice_isA_packet\0A\00"
@.str.3 = [55 x i8] c"Error: Failed to receive ice_isA_packet success reply\0A\00"
define i32 @murmur_connect(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca [56 x i8]
store i8* %0, i8** %3
%7 = bitcast [56 x i8]* %6 to i8*
%8 = load i8*, i8** %3
%9 = call i32 @sock_connect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %43
13: ; preds = %1
%14 = load i32, i32* %4
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%16 = call i32 @sock_read(i32 %14, i8* %15, i32 512)
%17 = icmp ne i32 %16, 14
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %40
21: ; preds = %13
%22 = load i32, i32* %4
%23 = getelementptr inbounds [56 x i8], [56 x i8]* %6, i64 0, i64 0
%24 = call i32 @sock_write(i32 %22, i8* %23, i32 56)
%25 = sext i32 %24 to i64
%26 = icmp ne i64 %25, 56
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %40
30: ; preds = %21
%31 = load i32, i32* %4
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%33 = call i32 @sock_read(i32 %31, i8* %32, i32 512)
%34 = icmp ne i32 %33, 26
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
br label %40
38: ; preds = %30
%39 = load i32, i32* %4
store i32 %39, i32* %2
br label %43
40: ; preds = %35, %27, %18
%41 = load i32, i32* %4
%42 = call i32 @close(i32 %41)
store i32 -1, i32* %2
br label %43
43: ; preds = %40, %38, %12
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@__const.murmur_connect.ice_isA_packet = [56 x i8] c"IceP\01\00\01\00\00\008\00\00\00\01\00\00\00\04Meta\00\00\07ice_isA\01\00\15\00\00\00\01\00\0E::Murmur::Meta"
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"Error: Failed to receive validate_packet\0A\00"
@.str.2 = [38 x i8] c"Error: Failed to send ice_isA_packet\0A\00"
@.str.3 = [55 x i8] c"Error: Failed to receive ice_isA_packet success reply\0A\00"
define i32 @murmur_connect(i8* %0) {
%2 = alloca [512 x i8]
%3 = alloca [56 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [56 x i8], [56 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @sock_connect(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %1
%9 = call i32 @sock_read(i32 %6, i8* %4, i32 512)
%10 = icmp eq i32 %9, 14
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = call i32 @sock_write(i32 %6, i8* %5, i32 56)
%13 = icmp eq i32 %12, 56
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @sock_read(i32 %6, i8* %4, i32 512)
%16 = icmp eq i32 %15, 26
br i1 %16, label %22, label %17
17: ; preds = %14, %11, %8
%18 = phi i8* [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), %11 ], [ getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), %14 ]
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* %18)
%21 = call i32 @close(i32 %6)
br label %22
22: ; preds = %14, %1, %17
%23 = phi i32 [ -1, %17 ], [ -1, %1 ], [ %6, %14 ]
ret i32 %23
}