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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ *connect_daemon(char *);
int /*<<< orphan*/ exit_status(int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
void send_to_daemon(const char *buffer) {
  FILE *fp;
  int n, c;
  fp = connect_daemon("/var/run/payproc/dameon");
  if (!fp)
    exit_status(500, "Error connecting payprocd");
  fputs("PPIPNHD\nRequest: ", fp);
  n = 9;
  while ((c = *buffer++)) {
    if (n == 1024) {
      putc('\n', fp);
      putc(' ', fp);
      n = 0;
    }
    putc(c, fp);
    n++;
  }
  putc('\n', fp);
  putc('\n', fp);
  if (ferror(fp))
    exit_status(500, "Error writing to payprocd");
  c = fgetc(fp);
  if (c != 'O')
    exit_status(500, "Error talking to payprocd");
  while (getc(fp) != EOF)
    ;
  fclose(fp);
}


x86 assembly (clang, -O0):
<send_to_daemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe6d(%rip),%rdi
call   1050 <connect_daemon@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b8 <send_to_daemon+0x38>
mov    $0x1f4,%edi
lea    0xe65(%rip),%rsi
call   1060 <exit_status@plt>
mov    -0x10(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1070 <fputs@plt>
movl   $0x9,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     123a <send_to_daemon+0xba>
cmpl   $0x400,-0x14(%rbp)
jne    121d <send_to_daemon+0x9d>
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   1090 <putc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x20,%edi
call   1090 <putc@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1090 <putc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cf <send_to_daemon+0x4f>
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   1090 <putc@plt>
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   1090 <putc@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     127a <send_to_daemon+0xfa>
mov    $0x1f4,%edi
lea    0xdcf(%rip),%rsi
call   1060 <exit_status@plt>
mov    -0x10(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x4f,-0x18(%rbp)
je     12a1 <send_to_daemon+0x121>
mov    $0x1f4,%edi
lea    0xdc2(%rip),%rsi
call   1060 <exit_status@plt>
jmp    12a6 <send_to_daemon+0x126>
mov    -0x10(%rbp),%rdi
call   10a0 <getc@plt>
mov    0x2d32(%rip),%rcx
cmp    (%rcx),%rax
je     12c4 <send_to_daemon+0x144>
jmp    12a6 <send_to_daemon+0x126>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_to_daemon>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xe6f(%rip),%rdi
call   1050 <connect_daemon@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11af <send_to_daemon+0x2f>
lea    0xe73(%rip),%rsi
mov    $0x1f4,%edi
call   1060 <exit_status@plt>
lea    0xe7c(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
mov    (%r15),%bl
test   %bl,%bl
je     1220 <send_to_daemon+0xa0>
add    $0x1,%r15
mov    $0x9,%ebp
jmp    11fa <send_to_daemon+0x7a>
nopw   0x0(%rax,%rax,1)
movsbl %bl,%edi
mov    %r14,%rsi
call   1080 <putc@plt>
add    $0x1,%ebp
movzbl (%r15),%ebx
add    $0x1,%r15
test   %bl,%bl
je     1220 <send_to_daemon+0xa0>
cmp    $0x400,%ebp
jne    11e0 <send_to_daemon+0x60>
mov    $0xa,%edi
mov    %r14,%rsi
call   1080 <putc@plt>
mov    $0x20,%edi
mov    %r14,%rsi
call   1080 <putc@plt>
xor    %ebp,%ebp
jmp    11e0 <send_to_daemon+0x60>
mov    $0xa,%edi
mov    %r14,%rsi
call   1080 <putc@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   1080 <putc@plt>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1258 <send_to_daemon+0xd8>
lea    0xdf6(%rip),%rsi
mov    $0x1f4,%edi
call   1060 <exit_status@plt>
mov    %r14,%rdi
call   1070 <fgetc@plt>
cmp    $0x4f,%eax
je     1276 <send_to_daemon+0xf6>
lea    0xdf2(%rip),%rsi
mov    $0x1f4,%edi
call   1060 <exit_status@plt>
mov    0x2d6b(%rip),%rbx
nopl   (%rax)
mov    %r14,%rdi
call   10a0 <getc@plt>
cmp    (%rbx),%rax
jne    1280 <send_to_daemon+0x100>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"/var/run/payproc/dameon\00"
@.str.1 = [26 x i8] c"Error connecting payprocd\00"
@.str.2 = [18 x i8] c"PPIPNHD\0ARequest: \00"
@.str.3 = [26 x i8] c"Error writing to payprocd\00"
@.str.4 = [26 x i8] c"Error talking to payprocd\00"
@EOF = global i64 0
define void @send_to_daemon(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32* @connect_daemon(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @exit_status(i32 500, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load i32*, i32** %3
%13 = call i32 @fputs(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32* %12)
store i32 9, i32* %4
br label %14
14: ; preds = %28, %11
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %2
%17 = load i8, i8* %15
%18 = sext i8 %17 to i32
store i32 %18, i32* %5
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %14
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 1024
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32*, i32** %3
%25 = call i32 @putc(i8 signext 10, i32* %24)
%26 = load i32*, i32** %3
%27 = call i32 @putc(i8 signext 32, i32* %26)
store i32 0, i32* %4
br label %28
28: ; preds = %23, %20
%29 = load i32, i32* %5
%30 = trunc i32 %29 to i8
%31 = load i32*, i32** %3
%32 = call i32 @putc(i8 signext %30, i32* %31)
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %14
35: ; preds = %14
%36 = load i32*, i32** %3
%37 = call i32 @putc(i8 signext 10, i32* %36)
%38 = load i32*, i32** %3
%39 = call i32 @putc(i8 signext 10, i32* %38)
%40 = load i32*, i32** %3
%41 = call i64 @ferror(i32* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %35
%44 = call i32 @exit_status(i32 500, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43, %35
%46 = load i32*, i32** %3
%47 = call i32 @fgetc(i32* %46)
store i32 %47, i32* %5
%48 = load i32, i32* %5
%49 = icmp ne i32 %48, 79
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = call i32 @exit_status(i32 500, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %50, %45
br label %53
53: ; preds = %58, %52
%54 = load i32*, i32** %3
%55 = call i64 @getc(i32* %54)
%56 = load i64, i64* @EOF
%57 = icmp ne i64 %55, %56
br i1 %57, label %58, label %59
58: ; preds = %53
br label %53
59: ; preds = %53
%60 = load i32*, i32** %3
%61 = call i32 @fclose(i32* %60)
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"/var/run/payproc/dameon\00"
@.str.1 = [26 x i8] c"Error connecting payprocd\00"
@.str.2 = [18 x i8] c"PPIPNHD\0ARequest: \00"
@.str.3 = [26 x i8] c"Error writing to payprocd\00"
@.str.4 = [26 x i8] c"Error talking to payprocd\00"
@EOF = global i64 0
define void @send_to_daemon(i8* nocapture %0) {
%2 = tail call i32* @connect_daemon(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @exit_status(i32 500, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 17, i64 1, i32* %2)
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %6, %19
%11 = phi i8 [ %23, %19 ], [ %8, %6 ]
%12 = phi i8* [ %14, %19 ], [ %0, %6 ]
%13 = phi i32 [ %22, %19 ], [ 9, %6 ]
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = icmp eq i32 %13, 1024
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = tail call i32 @putc(i8 signext 10, i32* %2)
%18 = tail call i32 @putc(i8 signext 32, i32* %2)
br label %19
19: ; preds = %16, %10
%20 = phi i32 [ 0, %16 ], [ %13, %10 ]
%21 = tail call i32 @putc(i8 signext %11, i32* %2)
%22 = add nsw i32 %20, 1
%23 = load i8, i8* %14
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %10
25: ; preds = %19, %6
%26 = tail call i32 @putc(i8 signext 10, i32* %2)
%27 = tail call i32 @putc(i8 signext 10, i32* %2)
%28 = tail call i64 @ferror(i32* %2)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %25
%31 = tail call i32 @exit_status(i32 500, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = tail call i32 @fgetc(i32* %2)
%34 = icmp eq i32 %33, 79
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = tail call i32 @exit_status(i32 500, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
br label %38
38: ; preds = %37, %38
%39 = tail call i64 @getc(i32* %2)
%40 = load i64, i64* @EOF
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %38
42: ; preds = %38
%43 = tail call i32 @fclose(i32* %2)
ret void
}