#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ MSG_WAITALL;
int O_CREAT;
int O_WRONLY;
char *__make_command(char const *, char const *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
int open(char const *, int, int);
int /*<<< orphan*/ perror(char *);
size_t recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sendall(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
size_t writeall(int, char const *, size_t);
int __process(int fd, const char *tag, const char *ftemp, const char *data,
              size_t len) {
  char *p;
  int f;
  ssize_t n;
  char buf[8];
  f = open(ftemp, O_WRONLY | O_CREAT, 0644);
  if (f == -1) {
    perror("comlogger: open");
    exit(-1);
  }
  n = writeall(f, data, len);
  if (n != len) {
    perror("comlogger: write");
    exit(-1);
  }
  close(f);
  p = __make_command(tag, ftemp, 1);
  if (!p) {
    perror("comlogger: __make_command");
    exit(-1);
  }
  sendall(fd, p, strlen(p), 0);
  free(p);
  n = recv(fd, buf, 4, MSG_WAITALL);
  if (n <= 0) {
    perror("comlogger: recv");
    exit(-1);
  }
  buf[n] = '\0';
  return strcmp(buf, "OK\r\n");
}


x86 assembly (clang, -O0):
<__process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
mov    0x2e19(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   10b0 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    120e <__process+0x5e>
lea    0xe01(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x34(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <writeall@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1246 <__process+0x96>
lea    0xdd9(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1090 <__make_command@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1285 <__process+0xd5>
lea    0xdab(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10a0 <sendall@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    0x2d0d(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%edx
call   1040 <recv@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
ja     12f4 <__process+0x144>
lea    0xd56(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x40(%rbp),%rax
movb   $0x0,-0x48(%rbp,%rax,1)
lea    -0x48(%rbp),%rdi
lea    0xd43(%rip),%rsi
call   1080 <strcmp@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__process>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbp
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%r15
mov    %edi,%r14d
mov    0x2df7(%rip),%rax
mov    0x2e20(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rdx,%rdi
mov    $0x1a4,%edx
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     1288 <__process+0xd8>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1050 <writeall@plt>
cmp    %rbp,%rax
jne    1291 <__process+0xe1>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
call   1090 <__make_command@plt>
test   %rax,%rax
je     129a <__process+0xea>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10a0 <sendall@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x4,%edx
call   1040 <recv@plt>
test   %rax,%rax
je     12a3 <__process+0xf3>
movb   $0x0,(%rsp,%rax,1)
lea    0xdda(%rip),%rsi
mov    %rsp,%rdi
call   1080 <strcmp@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd71(%rip),%rdi
jmp    12aa <__process+0xfa>
lea    0xd78(%rip),%rdi
jmp    12aa <__process+0xfa>
lea    0xd80(%rip),%rdi
jmp    12aa <__process+0xfa>
lea    0xd91(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [16 x i8] c"comlogger: open\00"
@.str.1 = [17 x i8] c"comlogger: write\00"
@.str.2 = [26 x i8] c"comlogger: __make_command\00"
@MSG_WAITALL = global i32 0
@.str.3 = [16 x i8] c"comlogger: recv\00"
@.str.4 = [5 x i8] c"OK\0D\0A\00"
define i32 @__process(i32 %0, i8* %1, i8* %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i64
%14 = alloca [8 x i8]
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%15 = load i8*, i8** %8
%16 = load i32, i32* @O_WRONLY
%17 = load i32, i32* @O_CREAT
%18 = or i32 %16, %17
%19 = call i32 @open(i8* %15, i32 %18, i32 420)
store i32 %19, i32* %12
%20 = load i32, i32* %12
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %5
%23 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %5
%26 = load i32, i32* %12
%27 = load i8*, i8** %9
%28 = load i64, i64* %10
%29 = call i64 @writeall(i32 %26, i8* %27, i64 %28)
store i64 %29, i64* %13
%30 = load i64, i64* %13
%31 = load i64, i64* %10
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %25
%37 = load i32, i32* %12
%38 = call i32 @close(i32 %37)
%39 = load i8*, i8** %7
%40 = load i8*, i8** %8
%41 = call i8* @__make_command(i8* %39, i8* %40, i32 1)
store i8* %41, i8** %11
%42 = load i8*, i8** %11
%43 = icmp ne i8* %42, null
br i1 %43, label %47, label %44
44: ; preds = %36
%45 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 -1)
unreachable
47: ; preds = %36
%48 = load i32, i32* %6
%49 = load i8*, i8** %11
%50 = load i8*, i8** %11
%51 = call i32 @strlen(i8* %50)
%52 = call i32 @sendall(i32 %48, i8* %49, i32 %51, i32 0)
%53 = load i8*, i8** %11
%54 = call i32 @free(i8* %53)
%55 = load i32, i32* %6
%56 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 0
%57 = load i32, i32* @MSG_WAITALL
%58 = call i64 @recv(i32 %55, i8* %56, i32 4, i32 %57)
store i64 %58, i64* %13
%59 = load i64, i64* %13
%60 = icmp ule i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %47
%62 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%63 = call i32 @exit(i32 -1)
unreachable
64: ; preds = %47
%65 = load i64, i64* %13
%66 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 %65
store i8 0, i8* %66
%67 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 0
%68 = call i32 @strcmp(i8* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret i32 %68
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [16 x i8] c"comlogger: open\00"
@.str.1 = [17 x i8] c"comlogger: write\00"
@.str.2 = [26 x i8] c"comlogger: __make_command\00"
@MSG_WAITALL = global i32 0
@.str.3 = [16 x i8] c"comlogger: recv\00"
@.str.4 = [5 x i8] c"OK\0D\0A\00"
define i32 @__process(i32 %0, i8* %1, i8* %2, i8* %3, i64 %4) {
%6 = alloca [8 x i8]
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%8 = load i32, i32* @O_WRONLY
%9 = load i32, i32* @O_CREAT
%10 = or i32 %9, %8
%11 = tail call i32 @open(i8* %2, i32 %10, i32 420)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %5
%14 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %5
%17 = tail call i64 @writeall(i32 %11, i8* %3, i64 %4)
%18 = icmp eq i64 %17, %4
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %16
%23 = tail call i32 @close(i32 %11)
%24 = tail call i8* @__make_command(i8* %1, i8* %2, i32 1)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @exit(i32 -1)
unreachable
29: ; preds = %22
%30 = tail call i32 @strlen(i8* %24)
%31 = tail call i32 @sendall(i32 %0, i8* %24, i32 %30, i32 0)
%32 = tail call i32 @free(i8* %24)
%33 = load i32, i32* @MSG_WAITALL
%34 = call i64 @recv(i32 %0, i8* %7, i32 4, i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %29
%40 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 %34
store i8 0, i8* %40
%41 = call i32 @strcmp(i8* %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret i32 %41
}