#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 */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ write(int, char *, int /*<<< orphan*/);
int writeln(char *line, int cliFd) {
  char lbuf[512];
  bzero(lbuf, 512);
  if (line != NULL) {
    strcpy(lbuf, line);
    strcat(lbuf, "\r\n");
    if (write(cliFd, lbuf, strlen(lbuf)) < 0) {
      perror("Writing on socket was not successful.\n");
      return 0;
    } else
      return 1;
  } else {
    if (write(cliFd, "\r\n", strlen("\r\n")) > 0)
      return 1;
    else
      return 0;
  }
}


x86 assembly (clang, -O0):
<writeln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x220(%rbp),%rdi
mov    $0x200,%esi
call   1070 <bzero@plt>
cmpq   $0x0,-0x10(%rbp)
je     1216 <writeln+0xb6>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x220(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x22c(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x228(%rbp)
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x22c(%rbp),%edi
mov    -0x228(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    120a <writeln+0xaa>
lea    0xe0a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    125c <writeln+0xfc>
movl   $0x1,-0x4(%rbp)
jmp    125c <writeln+0xfc>
mov    -0x14(%rbp),%eax
mov    %eax,-0x230(%rbp)
lea    0xdda(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x230(%rbp),%edi
mov    %eax,%edx
lea    0xdc6(%rip),%rsi
call   1040 <write@plt>
cmp    $0x0,%rax
jle    1255 <writeln+0xf5>
movl   $0x1,-0x4(%rbp)
jmp    125c <writeln+0xfc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeln>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x200,%esi
call   1070 <bzero@plt>
test   %rbx,%rbx
je     11d2 <writeln+0x72>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe68(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strcat@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jns    11f9 <writeln+0x99>
lea    0xe3a(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
jmp    11f9 <writeln+0x99>
lea    0xe27(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setg   %al
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [39 x i8] c"Writing on socket was not successful.\0A\00"
define i32 @writeln(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [512 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%8 = call i32 @bzero(i8* %7, i32 512)
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %26
11: ; preds = %2
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%13 = load i8*, i8** %4
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %5
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = call i64 @write(i32 %17, i8* %18, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %11
%24 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %33
25: ; preds = %11
store i32 1, i32* %3
br label %33
26: ; preds = %2
%27 = load i32, i32* %5
%28 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%29 = call i64 @write(i32 %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = icmp sgt i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i32 1, i32* %3
br label %33
32: ; preds = %26
store i32 0, i32* %3
br label %33
33: ; preds = %32, %31, %25, %23
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [39 x i8] c"Writing on socket was not successful.\0A\00"
define i32 @writeln(i8* %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i32 @bzero(i8* %4, i32 512)
%6 = icmp eq i8* %0, null
br i1 %6, label %15, label %7
7: ; preds = %2
%8 = call i32 @strcpy(i8* %4, i8* %0)
%9 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @strlen(i8* %4)
%11 = call i64 @write(i32 %1, i8* %4, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %7
%14 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %20
15: ; preds = %2
%16 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = tail call i64 @write(i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = icmp sgt i64 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %15, %7, %13
%21 = phi i32 [ 0, %13 ], [ 1, %7 ], [ %19, %15 ]
ret i32 %21
}