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

/* Variables and functions */
char *ErrLogStrTime();
int TCPIPMsgRecv(int, int *, int);
int TCPIPMsgSend(int, ...);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int /*<<< orphan*/ stderr;
int strlen(char *);
int ErrLog(int sock, char *name, char *buffer) {
  int msg, s;
  size_t nlen, blen;
  nlen = strlen(name) + 1;
  blen = strlen(buffer) + 1;
  msg = 'M';
  s = TCPIPMsgSend(sock, &msg, sizeof(int));
  if (s != sizeof(int)) {
    fprintf(stderr, "WARNING: Error not logged\n");
    fprintf(stderr, "%s: %d : %s :%s\n", ErrLogStrTime(), getpid(), name,
            buffer);
    return -1;
  }
  s = TCPIPMsgSend(sock, &nlen, sizeof(size_t));
  s = TCPIPMsgSend(sock, &blen, sizeof(size_t));
  s = TCPIPMsgSend(sock, name, nlen);
  s = TCPIPMsgSend(sock, buffer, blen);
  s = TCPIPMsgRecv(sock, &msg, sizeof(int));
  fprintf(stderr, "%s: %d : %s :%s\n", ErrLogStrTime(), getpid(), name, buffer);
  if ((s != sizeof(int)) || (msg != 'O')) {
    fprintf(stderr, "WARNING: Error not logged\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ErrLog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x30(%rbp)
movl   $0x4d,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1060 <TCPIPMsgSend@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    $0x4,%rax
je     1222 <ErrLog+0xc2>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1070 <ErrLogStrTime@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %eax,%ecx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130b <ErrLog+0x1ab>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1060 <TCPIPMsgSend@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1060 <TCPIPMsgSend@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1060 <TCPIPMsgSend@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    $0x0,%al
call   1060 <TCPIPMsgSend@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1080 <TCPIPMsgRecv@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    $0x0,%al
call   1070 <ErrLogStrTime@plt>
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %eax,%ecx
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    0xd59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movslq -0x20(%rbp),%rax
cmp    $0x4,%rax
jne    12e1 <ErrLog+0x181>
cmpl   $0x4f,-0x1c(%rbp)
je     1304 <ErrLog+0x1a4>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xd0f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130b <ErrLog+0x1ab>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ErrLog>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
mov    %rsi,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,0x10(%rsp)
mov    %r14,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,0x8(%rsp)
movl   $0x4d,0x4(%rsp)
xor    %r13d,%r13d
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <TCPIPMsgSend@plt>
cmp    $0x4,%eax
jne    1278 <ErrLog+0x118>
lea    0x10(%rsp),%rsi
mov    $0x8,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <TCPIPMsgSend@plt>
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <TCPIPMsgSend@plt>
mov    0x10(%rsp),%rdx
mov    %ebx,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <TCPIPMsgSend@plt>
mov    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <TCPIPMsgSend@plt>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1080 <TCPIPMsgRecv@plt>
mov    %eax,%r12d
mov    0x2dbc(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1070 <ErrLogStrTime@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xddd(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
mov    %r15,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    $0x4,%r12d
jne    125f <ErrLog+0xff>
cmpl   $0x4f,0x4(%rsp)
je     12c3 <ErrLog+0x163>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12bd <ErrLog+0x15d>
mov    0x2d61(%rip),%rbx
mov    (%rbx),%edi
lea    0xd78(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%ebx
xor    %eax,%eax
call   1070 <ErrLogStrTime@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xd72(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
mov    %r15,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"WARNING: Error not logged\0A\00"
@.str.1 = [17 x i8] c"%s: %d : %s :%s\0A\00"
define i32 @ErrLog(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = bitcast i32* %4 to i8*
%8 = bitcast i64* %5 to i8*
%9 = bitcast i64* %6 to i8*
%10 = tail call i32 @strlen(i8* %1)
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
store i64 %12, i64* %5
%13 = tail call i32 @strlen(i8* %2)
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
store i64 %15, i64* %6
store i32 77, i32* %4
%16 = call i32 (i32, ...) @TCPIPMsgSend(i32 %0, i32* %4, i64 4)
%17 = icmp eq i32 %16, 4
br i1 %17, label %25, label %18
18: ; preds = %3
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = call i8* (...) @ErrLogStrTime()
%23 = call i32 (...) @getpid()
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %23, i8* %1, i8* %2)
br label %44
25: ; preds = %3
%26 = call i32 (i32, ...) @TCPIPMsgSend(i32 %0, i64* %5, i64 8)
%27 = call i32 (i32, ...) @TCPIPMsgSend(i32 %0, i64* %6, i64 8)
%28 = load i64, i64* %5
%29 = call i32 (i32, ...) @TCPIPMsgSend(i32 %0, i8* %1, i64 %28)
%30 = load i64, i64* %6
%31 = call i32 (i32, ...) @TCPIPMsgSend(i32 %0, i8* %2, i64 %30)
%32 = call i32 @TCPIPMsgRecv(i32 %0, i32* %4, i32 4)
%33 = load i32, i32* @stderr
%34 = call i8* (...) @ErrLogStrTime()
%35 = call i32 (...) @getpid()
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %34, i32 %35, i8* %1, i8* %2)
%37 = icmp ne i32 %32, 4
%38 = load i32, i32* %4
%39 = icmp ne i32 %38, 79
%40 = select i1 %37, i1 true, i1 %39
br i1 %40, label %41, label %44
41: ; preds = %25
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %44
44: ; preds = %25, %41, %18
%45 = phi i32 [ -1, %18 ], [ -1, %41 ], [ 0, %25 ]
ret i32 %45
}