#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 */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
int write(int, char *, int);
int sendMSG(int sockfd, char *handle) {
  char buffer[512];
  char message[501];
  int n = 0;
  bzero(message, 501);
  bzero(buffer, 512);
  strcat(buffer, handle);
  strcat(buffer, " > ");
  printf("%s > ", handle);
  fgets(message, sizeof(message), stdin);
  message[strlen(message) - 1] = '\0';
  if (strstr(message, "quit") != NULL) {
    n = write(sockfd, message, strlen(message));
    if (n < 0)
      error("ERROR writing to socket");
    return 1;
  } else {
    strcat(buffer, message);
    n = write(sockfd, buffer, strlen(buffer));
    if (n < 0)
      error("ERROR writing to socket");
  }
}


x86 assembly (clang, -O0):
<sendMSG>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x1f5,%esi
call   1080 <bzero@plt>
lea    -0x210(%rbp),%rdi
mov    $0x200,%esi
call   1080 <bzero@plt>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x210(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%edx
mov    $0x1f5,%esi
call   1060 <fgets@plt>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
lea    0xdd4(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     12a3 <sendMSG+0x123>
mov    -0x8(%rbp),%eax
mov    %eax,-0x424(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x424(%rbp),%edi
mov    -0x420(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    1297 <sendMSG+0x117>
lea    0xd79(%rip),%rdi
call   1070 <error@plt>
movl   $0x1,-0x4(%rbp)
jmp    1311 <sendMSG+0x191>
lea    -0x210(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x434(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x430(%rbp)
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x434(%rbp),%edi
mov    -0x430(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    130c <sendMSG+0x18c>
lea    0xd04(%rip),%rdi
call   1070 <error@plt>
jmp    1311 <sendMSG+0x191>
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMSG>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1f5,%esi
call   1080 <bzero@plt>
lea    0x200(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1080 <bzero@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strcat@plt>
lea    0xe38(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
lea    0xe27(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0x1f5,%esi
call   1060 <fgets@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
lea    0xdf8(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     1220 <sendMSG+0xa0>
mov    %rsp,%rbx
jmp    1233 <sendMSG+0xb3>
lea    0x200(%rsp),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    1258 <sendMSG+0xd8>
lea    0xdb8(%rip),%rdi
call   1070 <error@plt>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c" > \00"
@.str.1 = [6 x i8] c"%s > \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"quit\00"
@.str.3 = [24 x i8] c"ERROR writing to socket\00"
define i32 @sendMSG(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [512 x i8]
%7 = alloca [501 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %8
%9 = getelementptr inbounds [501 x i8], [501 x i8]* %7, i64 0, i64 0
%10 = call i32 @bzero(i8* %9, i32 501)
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%12 = call i32 @bzero(i8* %11, i32 512)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%14 = load i8*, i8** %5
%15 = call i32 @strcat(i8* %13, i8* %14)
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%17 = call i32 @strcat(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%18 = load i8*, i8** %5
%19 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [501 x i8], [501 x i8]* %7, i64 0, i64 0
%21 = load i32, i32* @stdin
%22 = call i32 @fgets(i8* %20, i32 501, i32 %21)
%23 = getelementptr inbounds [501 x i8], [501 x i8]* %7, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [501 x i8], [501 x i8]* %7, i64 0, i64 %26
store i8 0, i8* %27
%28 = getelementptr inbounds [501 x i8], [501 x i8]* %7, i64 0, i64 0
%29 = call i32* @strstr(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %42
31: ; preds = %2
%32 = load i32, i32* %4
%33 = getelementptr inbounds [501 x i8], [501 x i8]* %7, i64 0, i64 0
%34 = getelementptr inbounds [501 x i8], [501 x i8]* %7, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @write(i32 %32, i8* %33, i32 %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %31
%40 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %31
store i32 1, i32* %3
br label %56
42: ; preds = %2
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%44 = getelementptr inbounds [501 x i8], [501 x i8]* %7, i64 0, i64 0
%45 = call i32 @strcat(i8* %43, i8* %44)
%46 = load i32, i32* %4
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = call i32 @write(i32 %46, i8* %47, i32 %49)
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %42
%54 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %53, %42
br label %56
56: ; preds = %41, %55
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [4 x i8] c" > \00"
@.str.1 = [6 x i8] c"%s > \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"quit\00"
@.str.3 = [24 x i8] c"ERROR writing to socket\00"
define i32 @sendMSG(i32 %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = alloca [501 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [501 x i8], [501 x i8]* %4, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 501)
%8 = call i32 @bzero(i8* %5, i32 512)
%9 = call i32 @strcat(i8* %5, i8* %1)
%10 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %6, i32 501, i32 %12)
%14 = call i32 @strlen(i8* %6)
%15 = add nsw i32 %14, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [501 x i8], [501 x i8]* %4, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32* @strstr(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %24, label %20
20: ; preds = %2
%21 = call i32 @strlen(i8* %6)
%22 = call i32 @write(i32 %0, i8* %6, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %29, label %31
24: ; preds = %2
%25 = call i32 @strcat(i8* %5, i8* %6)
%26 = call i32 @strlen(i8* %5)
%27 = call i32 @write(i32 %0, i8* %5, i32 %26)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24, %20
%30 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %24, %20
ret i32 1
}