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

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
double difftime(int /*<<< orphan*/, int /*<<< orphan*/);
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 /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int write(int, char *, int);
int sendMSG(int sockfd, char *handle) {
  time_t start, end;
  char message[501];
  char buffer[512];
  double dif;
  int n = 0;
  bzero(buffer, 512);
  bzero(message, 501);
  strcat(buffer, handle);
  strcat(buffer, " > ");
  time(&start);
  printf("%s > ", handle);
  fgets(message, sizeof(message), stdin);
  message[strlen(message) - 1] = '\0';
  time(&end);
  dif = difftime(end, start);
  if (dif > 180.0) {
    bzero(message, 501);
    strcpy(message, "quit");
    n = write(sockfd, message, strlen(message));
    if (n < 0)
      error("ERROR writing to socket");
    return 1;
  } else 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");
  }
  return 0;
}


x86 assembly (clang, -O0):
<sendMSG>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x41c(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x200,%esi
call   10b0 <bzero@plt>
lea    -0x210(%rbp),%rdi
mov    $0x1f5,%esi
call   10b0 <bzero@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10c0 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   10c0 <strcat@plt>
lea    -0x14(%rbp),%rdi
call   1090 <time@plt>
mov    -0x10(%rbp),%rsi
lea    0xde3(%rip),%rdi
call   1060 <printf@plt>
lea    -0x210(%rbp),%rdi
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
mov    $0x1f5,%esi
call   1080 <fgets@plt>
lea    -0x210(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x18(%rbp),%rdi
call   1090 <time@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1070 <difftime@plt>
movsd  %xmm0,-0x418(%rbp)
ff
movsd  -0x418(%rbp),%xmm0
ff
movsd  0xd77(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1319 <sendMSG+0x169>
lea    -0x210(%rbp),%rdi
mov    $0x1f5,%esi
call   10b0 <bzero@plt>
lea    -0x210(%rbp),%rdi
lea    0xd5c(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x42c(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x210(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x42c(%rbp),%edi
mov    -0x428(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x41c(%rbp)
cmpl   $0x0,-0x41c(%rbp)
jge    130d <sendMSG+0x15d>
lea    0xd0b(%rip),%rdi
call   10a0 <error@plt>
movl   $0x1,-0x4(%rbp)
jmp    1412 <sendMSG+0x262>
lea    -0x210(%rbp),%rdi
lea    0xce7(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     1398 <sendMSG+0x1e8>
mov    -0x8(%rbp),%eax
mov    %eax,-0x43c(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x438(%rbp)
lea    -0x210(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x41c(%rbp)
cmpl   $0x0,-0x41c(%rbp)
jge    138c <sendMSG+0x1dc>
lea    0xc8c(%rip),%rdi
call   10a0 <error@plt>
movl   $0x1,-0x4(%rbp)
jmp    1412 <sendMSG+0x262>
lea    -0x410(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x44c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x44c(%rbp),%edi
mov    -0x448(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x41c(%rbp)
cmpl   $0x0,-0x41c(%rbp)
jge    1401 <sendMSG+0x251>
lea    0xc17(%rip),%rdi
call   10a0 <error@plt>
jmp    1406 <sendMSG+0x256>
jmp    140b <sendMSG+0x25b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMSG>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
lea    0x210(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
call   10b0 <bzero@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x1f5,%esi
call   10b0 <bzero@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10c0 <strcat@plt>
lea    0xe0e(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
lea    0xc(%rsp),%rdi
call   1090 <time@plt>
lea    0xdf3(%rip),%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0x1f5,%esi
call   1080 <fgets@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
lea    0x8(%rsp),%rdi
call   1090 <time@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   1070 <difftime@plt>
ucomisd 0xd9e(%rip),%xmm0
jbe    1287 <sendMSG+0xd7>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1f5,%esi
call   10b0 <bzero@plt>
lea    0xd91(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    12a2 <sendMSG+0xf2>
lea    0xd80(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10d0 <strstr@plt>
test   %rax,%rax
je     12dc <sendMSG+0x12c>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    $0x1,%ebx
test   %eax,%eax
jns    12cc <sendMSG+0x11c>
lea    0xd4c(%rip),%rdi
call   10a0 <error@plt>
mov    %ebx,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x210(%rsp),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
xor    %ebx,%ebx
test   %eax,%eax
jns    12cc <sendMSG+0x11c>
jmp    12c0 <sendMSG+0x110>

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 i32
%7 = alloca i32
%8 = alloca [501 x i8]
%9 = alloca [512 x i8]
%10 = alloca double
%11 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %11
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%13 = call i32 @bzero(i8* %12, i32 512)
%14 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 0
%15 = call i32 @bzero(i8* %14, i32 501)
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = call i32 @strcat(i8* %16, i8* %17)
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @time(i32* %6)
%22 = load i8*, i8** %5
%23 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 0
%25 = load i32, i32* @stdin
%26 = call i32 @fgets(i8* %24, i32 501, i32 %25)
%27 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 %30
store i8 0, i8* %31
%32 = call i32 @time(i32* %7)
%33 = load i32, i32* %7
%34 = load i32, i32* %6
%35 = call double @difftime(i32 %33, i32 %34)
store double %35, double* %10
%36 = load double, double* %10
%37 = fcmp ogt double %36, 1.800000e+02
br i1 %37, label %38, label %53
38: ; preds = %2
%39 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 0
%40 = call i32 @bzero(i8* %39, i32 501)
%41 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 0
%42 = call i32 @strcpy(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* %4
%44 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 0
%45 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = call i32 @write(i32 %43, i8* %44, i32 %46)
store i32 %47, i32* %11
%48 = load i32, i32* %11
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %38
%51 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %50, %38
store i32 1, i32* %3
br label %84
53: ; preds = %2
%54 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 0
%55 = call i32* @strstr(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%56 = icmp ne i32* %55, null
br i1 %56, label %57, label %68
57: ; preds = %53
%58 = load i32, i32* %4
%59 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 0
%60 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = call i32 @write(i32 %58, i8* %59, i32 %61)
store i32 %62, i32* %11
%63 = load i32, i32* %11
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %57
%66 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %67
67: ; preds = %65, %57
store i32 1, i32* %3
br label %84
68: ; preds = %53
%69 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%70 = getelementptr inbounds [501 x i8], [501 x i8]* %8, i64 0, i64 0
%71 = call i32 @strcat(i8* %69, i8* %70)
%72 = load i32, i32* %4
%73 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%74 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%75 = call i32 @strlen(i8* %74)
%76 = call i32 @write(i32 %72, i8* %73, i32 %75)
store i32 %76, i32* %11
%77 = load i32, i32* %11
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %68
%80 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %81
81: ; preds = %79, %68
br label %82
82: ; preds = %81
br label %83
83: ; preds = %82
store i32 0, i32* %3
br label %84
84: ; preds = %83, %67, %52
%85 = load i32, i32* %3
ret i32 %85
}

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 i32
%4 = alloca i32
%5 = alloca [501 x i8]
%6 = alloca [512 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds [501 x i8], [501 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%11 = call i32 @bzero(i8* %10, i32 512)
%12 = call i32 @bzero(i8* %9, i32 501)
%13 = call i32 @strcat(i8* %10, i8* %1)
%14 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @time(i32* %3)
%16 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %9, i32 501, i32 %17)
%19 = call i32 @strlen(i8* %9)
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [501 x i8], [501 x i8]* %5, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 @time(i32* %4)
%24 = load i32, i32* %4
%25 = load i32, i32* %3
%26 = call double @difftime(i32 %24, i32 %25)
%27 = fcmp ogt double %26, 1.800000e+02
br i1 %27, label %28, label %34
28: ; preds = %2
%29 = call i32 @bzero(i8* %9, i32 501)
%30 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @strlen(i8* %9)
%32 = call i32 @write(i32 %0, i8* %9, i32 %31)
%33 = icmp slt i32 %32, 0
br i1 %33, label %46, label %49
34: ; preds = %2
%35 = call i32* @strstr(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = call i32 @strlen(i8* %9)
%39 = call i32 @write(i32 %0, i8* %9, i32 %38)
%40 = icmp slt i32 %39, 0
br i1 %40, label %46, label %49
41: ; preds = %34
%42 = call i32 @strcat(i8* %10, i8* %9)
%43 = call i32 @strlen(i8* %10)
%44 = call i32 @write(i32 %0, i8* %10, i32 %43)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41, %37, %28
%47 = phi i32 [ 1, %28 ], [ 1, %37 ], [ 0, %41 ]
%48 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %46, %41, %37, %28
%50 = phi i32 [ 1, %28 ], [ 1, %37 ], [ 0, %41 ], [ %47, %46 ]
ret i32 %50
}