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

/* Variables and functions */
int TCPIPMsgRecv(int, ...);
int TCPIPMsgSend(int, int *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
char *get_time();
char *malloc(size_t);
int /*<<< orphan*/ *open_file();
int /*<<< orphan*/ *stderr;
int operate(pid_t parent, int sock) {
  int s;
  int msg;
  size_t nlen, blen;
  char *name = NULL, *buf = NULL;
  FILE *fp = NULL;
  while (1) {
    s = TCPIPMsgRecv(sock, &msg, sizeof(int));
    if (s != sizeof(int))
      break;
    s = TCPIPMsgRecv(sock, &nlen, sizeof(size_t));
    if (s != sizeof(size_t))
      break;
    s = TCPIPMsgRecv(sock, &blen, sizeof(size_t));
    if (s != sizeof(size_t))
      break;
    name = malloc(nlen);
    if (name != NULL)
      buf = malloc(blen);
    if (buf != NULL) {
      s = TCPIPMsgRecv(sock, name, nlen);
      if (s != nlen)
        break;
      s = TCPIPMsgRecv(sock, buf, blen);
      if (s != blen)
        break;
      msg = 'O';
    } else
      msg = 'F';
    s = TCPIPMsgSend(sock, &msg, sizeof(int));
    fp = open_file();
    if (fp == NULL)
      fprintf(stderr, "WARNING : Error log not recording\n");
    if (fp != NULL)
      fprintf(fp, "%s : %s :%s\n", get_time(), name, buf);
    fprintf(stderr, "%s : %s :%s\n", get_time(), name, buf);
    if (fp != NULL)
      fclose(fp);
    if (name != NULL)
      free(name);
    if (buf != NULL)
      free(buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<operate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   10a0 <TCPIPMsgRecv@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x4,%rax
je     11cf <operate+0x4f>
jmp    13a0 <operate+0x220>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   10a0 <TCPIPMsgRecv@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x8,%rax
je     11f8 <operate+0x78>
jmp    13a0 <operate+0x220>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   10a0 <TCPIPMsgRecv@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x8,%rax
je     1221 <operate+0xa1>
jmp    13a0 <operate+0x220>
mov    -0x18(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1246 <operate+0xc6>
mov    -0x20(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12ad <operate+0x12d>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x0,%al
call   10a0 <TCPIPMsgRecv@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1279 <operate+0xf9>
jmp    13a0 <operate+0x220>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   10a0 <TCPIPMsgRecv@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     12a1 <operate+0x121>
jmp    13a0 <operate+0x220>
movl   $0x4f,-0x10(%rbp)
jmp    12b4 <operate+0x134>
movl   $0x46,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1090 <TCPIPMsgSend@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <open_file@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12f6 <operate+0x176>
mov    0x2cfb(%rip),%rax
mov    (%rax),%rdi
lea    0xd11(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpq   $0x0,-0x38(%rbp)
je     132d <operate+0x1ad>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1060 <get_time@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xcfd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1060 <get_time@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xccb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpq   $0x0,-0x38(%rbp)
je     1373 <operate+0x1f3>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     1387 <operate+0x207>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     139b <operate+0x21b>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    11a6 <operate+0x26>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<operate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rsp,%rsi
mov    $0x4,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   10a0 <TCPIPMsgRecv@plt>
cmp    $0x4,%eax
jne    1380 <operate+0x1f0>
mov    %rsp,%r14
xor    %r13d,%r13d
mov    %ebx,0x4(%rsp)
jmp    11ea <operate+0x5a>
cs nopw 0x0(%rax,%rax,1)
mov    $0x4,%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <TCPIPMsgRecv@plt>
cmp    $0x4,%eax
jne    1380 <operate+0x1f0>
mov    $0x8,%edx
mov    %ebx,%edi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   10a0 <TCPIPMsgRecv@plt>
cmp    $0x8,%eax
jne    1380 <operate+0x1f0>
mov    $0x8,%edx
mov    %ebx,%edi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   10a0 <TCPIPMsgRecv@plt>
cmp    $0x8,%eax
jne    1380 <operate+0x1f0>
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     1244 <operate+0xb4>
mov    0x8(%rsp),%rdi
call   1080 <malloc@plt>
mov    %rax,%r13
test   %r13,%r13
je     1290 <operate+0x100>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   10a0 <TCPIPMsgRecv@plt>
cltq
cmp    %rax,0x10(%rsp)
jne    1380 <operate+0x1f0>
mov    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    %r13,%rsi
xor    %eax,%eax
call   10a0 <TCPIPMsgRecv@plt>
movslq %eax,%rcx
mov    $0x4f,%eax
cmp    %rcx,0x8(%rsp)
je     1295 <operate+0x105>
jmp    1380 <operate+0x1f0>
nopw   0x0(%rax,%rax,1)
mov    $0x46,%eax
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1090 <TCPIPMsgSend@plt>
xor    %eax,%eax
call   1050 <open_file@plt>
test   %rax,%rax
je     1310 <operate+0x180>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <get_time@plt>
mov    %r14,%rdi
lea    0xd5c(%rip),%r12
mov    %r12,%rsi
mov    %rax,%rdx
mov    %r15,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%rbp
xor    %eax,%eax
call   1060 <get_time@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
mov    %r15,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    1356 <operate+0x1c6>
nopl   0x0(%rax,%rax,1)
mov    0x2cc9(%rip),%rbp
mov    0x0(%rbp),%rcx
mov    $0x22,%esi
mov    $0x1,%edx
lea    0xcd4(%rip),%rdi
call   10b0 <fwrite@plt>
mov    0x0(%rbp),%rbp
xor    %eax,%eax
call   1060 <get_time@plt>
mov    %rbp,%rdi
lea    0xcdd(%rip),%rsi
mov    %rax,%rdx
mov    %r15,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rsp,%r14
mov    0x4(%rsp),%ebx
test   %r15,%r15
je     136a <operate+0x1da>
mov    %r15,%rdi
call   1030 <free@plt>
test   %r13,%r13
je     11d0 <operate+0x40>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    11d0 <operate+0x40>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32* null
@.str = [35 x i8] c"WARNING : Error log not recording\0A\00"
@.str.1 = [13 x i8] c"%s : %s :%s\0A\00"
define i32 @operate(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* null, i8** %9
store i8* null, i8** %10
store i32* null, i32** %11
br label %12
12: ; preds = %2, %107
%13 = load i32, i32* %4
%14 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %13, i32* %6, i64 4)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = icmp ne i64 %16, 4
br i1 %17, label %18, label %19
18: ; preds = %12
br label %108
19: ; preds = %12
%20 = load i32, i32* %4
%21 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %20, i64* %7, i64 8)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = icmp ne i64 %23, 8
br i1 %24, label %25, label %26
25: ; preds = %19
br label %108
26: ; preds = %19
%27 = load i32, i32* %4
%28 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %27, i64* %8, i64 8)
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = icmp ne i64 %30, 8
br i1 %31, label %32, label %33
32: ; preds = %26
br label %108
33: ; preds = %26
%34 = load i64, i64* %7
%35 = call i8* @malloc(i64 %34)
store i8* %35, i8** %9
%36 = load i8*, i8** %9
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i64, i64* %8
%40 = call i8* @malloc(i64 %39)
store i8* %40, i8** %10
br label %41
41: ; preds = %38, %33
%42 = load i8*, i8** %10
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %65
44: ; preds = %41
%45 = load i32, i32* %4
%46 = load i8*, i8** %9
%47 = load i64, i64* %7
%48 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %45, i8* %46, i64 %47)
store i32 %48, i32* %5
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = load i64, i64* %7
%52 = icmp ne i64 %50, %51
br i1 %52, label %53, label %54
53: ; preds = %44
br label %108
54: ; preds = %44
%55 = load i32, i32* %4
%56 = load i8*, i8** %10
%57 = load i64, i64* %8
%58 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %55, i8* %56, i64 %57)
store i32 %58, i32* %5
%59 = load i32, i32* %5
%60 = sext i32 %59 to i64
%61 = load i64, i64* %8
%62 = icmp ne i64 %60, %61
br i1 %62, label %63, label %64
63: ; preds = %54
br label %108
64: ; preds = %54
store i32 79, i32* %6
br label %66
65: ; preds = %41
store i32 70, i32* %6
br label %66
66: ; preds = %65, %64
%67 = load i32, i32* %4
%68 = call i32 @TCPIPMsgSend(i32 %67, i32* %6, i32 4)
store i32 %68, i32* %5
%69 = call i32* (...) @open_file()
store i32* %69, i32** %11
%70 = load i32*, i32** %11
%71 = icmp eq i32* %70, null
br i1 %71, label %72, label %75
72: ; preds = %66
%73 = load i32*, i32** @stderr
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %75
75: ; preds = %72, %66
%76 = load i32*, i32** %11
%77 = icmp ne i32* %76, null
br i1 %77, label %78, label %84
78: ; preds = %75
%79 = load i32*, i32** %11
%80 = call i8* (...) @get_time()
%81 = load i8*, i8** %9
%82 = load i8*, i8** %10
%83 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %80, i8* %81, i8* %82)
br label %84
84: ; preds = %78, %75
%85 = load i32*, i32** @stderr
%86 = call i8* (...) @get_time()
%87 = load i8*, i8** %9
%88 = load i8*, i8** %10
%89 = call i32 (i32*, i8*, ...) @fprintf(i32* %85, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %86, i8* %87, i8* %88)
%90 = load i32*, i32** %11
%91 = icmp ne i32* %90, null
br i1 %91, label %92, label %95
92: ; preds = %84
%93 = load i32*, i32** %11
%94 = call i32 @fclose(i32* %93)
br label %95
95: ; preds = %92, %84
%96 = load i8*, i8** %9
%97 = icmp ne i8* %96, null
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = load i8*, i8** %9
%100 = call i32 @free(i8* %99)
br label %101
101: ; preds = %98, %95
%102 = load i8*, i8** %10
%103 = icmp ne i8* %102, null
br i1 %103, label %104, label %107
104: ; preds = %101
%105 = load i8*, i8** %10
%106 = call i32 @free(i8* %105)
br label %107
107: ; preds = %104, %101
br label %12
108: ; preds = %63, %53, %32, %25, %18
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [35 x i8] c"WARNING : Error log not recording\0A\00"
@.str.1 = [13 x i8] c"%s : %s :%s\0A\00"
define i32 @operate(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i32* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = bitcast i64* %5 to i8*
%9 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %1, i32* %3, i64 4)
%10 = icmp eq i32 %9, 4
br i1 %10, label %11, label %66
11: ; preds = %2, %63
%12 = phi i8* [ %26, %63 ], [ null, %2 ]
%13 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %1, i64* %4, i64 8)
%14 = icmp eq i32 %13, 8
br i1 %14, label %15, label %66
15: ; preds = %11
%16 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %1, i64* %5, i64 8)
%17 = icmp eq i32 %16, 8
br i1 %17, label %18, label %66
18: ; preds = %15
%19 = load i64, i64* %4
%20 = call i8* @malloc(i64 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i64, i64* %5
%24 = call i8* @malloc(i64 %23)
br label %25
25: ; preds = %22, %18
%26 = phi i8* [ %24, %22 ], [ %12, %18 ]
%27 = icmp eq i8* %26, null
br i1 %27, label %39, label %28
28: ; preds = %25
%29 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %1, i8* %20, i64 %19)
%30 = sext i32 %29 to i64
%31 = load i64, i64* %4
%32 = icmp eq i64 %31, %30
br i1 %32, label %33, label %66
33: ; preds = %28
%34 = load i64, i64* %5
%35 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %1, i8* %26, i64 %34)
%36 = sext i32 %35 to i64
%37 = load i64, i64* %5
%38 = icmp eq i64 %37, %36
br i1 %38, label %39, label %66
39: ; preds = %25, %33
%40 = phi i32 [ 79, %33 ], [ 70, %25 ]
store i32 %40, i32* %3
%41 = call i32 @TCPIPMsgSend(i32 %1, i32* %3, i32 4)
%42 = call i32* (...) @open_file()
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %50
44: ; preds = %39
%45 = load i32*, i32** @stderr
%46 = call i64 @fwrite(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i64 34, i64 1, i32* %45)
%47 = load i32*, i32** @stderr
%48 = call i8* (...) @get_time()
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %48, i8* %20, i8* %26)
br label %57
50: ; preds = %39
%51 = call i8* (...) @get_time()
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %51, i8* %20, i8* %26)
%53 = load i32*, i32** @stderr
%54 = call i8* (...) @get_time()
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %54, i8* %20, i8* %26)
%56 = call i32 @fclose(i32* %42)
br label %57
57: ; preds = %44, %50
br i1 %21, label %60, label %58
58: ; preds = %57
%59 = call i32 @free(i8* %20)
br label %60
60: ; preds = %58, %57
br i1 %27, label %63, label %61
61: ; preds = %60
%62 = call i32 @free(i8* %26)
br label %63
63: ; preds = %61, %60
%64 = call i32 (i32, ...) @TCPIPMsgRecv(i32 %1, i32* %3, i64 4)
%65 = icmp eq i32 %64, 4
br i1 %65, label %11, label %66
66: ; preds = %63, %11, %15, %28, %33, %2
ret i32 0
}