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

/* Variables and functions */
scalar_t__ lw_sock_send_str(int *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ recv_ok(int *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int lw_protocol_chat_talk(int *sock, char *text) {
  int result = 0;
  char message[1000];
  {
    {
      memset(((message)), 0, (sizeof(message)));
      snprintf(((message)), (sizeof(message)) - 1, (("%s '%s'")),
               (("CHATTALK")), ((text)));
      ((message))[(sizeof(message)) - 1] = '\0';
    };
  };
  if (*sock >= 0 && lw_sock_send_str(sock, message)) {
    if (recv_ok(sock)) {
      result = 1;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<lw_protocol_chat_talk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x400(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%r8
mov    $0x3e7,%esi
lea    0xe7c(%rip),%rdx
lea    0xe7d(%rip),%rcx
call   1040 <snprintf@plt>
movb   $0x0,-0x19(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jl     11da <lw_protocol_chat_talk+0x9a>
mov    -0x8(%rbp),%rdi
lea    -0x400(%rbp),%rsi
call   1060 <lw_sock_send_str@plt>
cmp    $0x0,%rax
je     11da <lw_protocol_chat_talk+0x9a>
mov    -0x8(%rbp),%rdi
call   1030 <recv_ok@plt>
cmp    $0x0,%rax
je     11d5 <lw_protocol_chat_talk+0x95>
movl   $0x1,-0x14(%rbp)
jmp    11da <lw_protocol_chat_talk+0x9a>
mov    -0x14(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lw_protocol_chat_talk>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3e8,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%r15
xor    %ebp,%ebp
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
lea    0xe92(%rip),%rdx
lea    0xe93(%rip),%rcx
mov    %r15,%rdi
mov    $0x3e7,%esi
mov    %r14,%r8
call   1040 <snprintf@plt>
movb   $0x0,0x3e7(%rsp)
cmpl   $0x0,(%rbx)
js     11b3 <lw_protocol_chat_talk+0x73>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <lw_sock_send_str@plt>
test   %rax,%rax
je     11b3 <lw_protocol_chat_talk+0x73>
mov    %rbx,%rdi
call   1030 <recv_ok@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s '%s'\00"
@.str.1 = [9 x i8] c"CHATTALK\00"
define i32 @lw_protocol_chat_talk(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [1000 x i8]
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 1000)
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 @snprintf(i8* %9, i32 999, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 999
store i8 0, i8* %12
%13 = load i32*, i32** %3
%14 = load i32, i32* %13
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %2
%17 = load i32*, i32** %3
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%19 = call i64 @lw_sock_send_str(i32* %17, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i32*, i32** %3
%23 = call i64 @recv_ok(i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 1, i32* %5
br label %26
26: ; preds = %25, %21
br label %27
27: ; preds = %26, %16, %2
%28 = load i32, i32* %5
ret i32 %28
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s '%s'\00"
@.str.1 = [9 x i8] c"CHATTALK\00"
define i32 @lw_protocol_chat_talk(i32* %0, i8* %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 1000)
%6 = call i32 @snprintf(i8* %4, i32 999, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 999
store i8 0, i8* %7
%8 = load i32, i32* %0
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = call i64 @lw_sock_send_str(i32* %0, i8* %4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = call i64 @recv_ok(i32* %0)
%15 = icmp ne i64 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %13, %10, %2
%18 = phi i32 [ 0, %10 ], [ 0, %2 ], [ %16, %13 ]
ret i32 %18
}