#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 strlen(char *);
int write(int, char *, int);
int write_line_to_socket(int c, char *the_line) {
  int status = 0;
  int result = 0;
  int count = 0;
  count = strlen(the_line);
  while (status != count) {
    result = write(c, the_line + status, count - status);
    if (result < 0)
      return result;
    status += result;
  }
  return (status);
}


x86 assembly (clang, -O0):
<write_line_to_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     119b <write_line_to_socket+0x7b>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
sub    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    118d <write_line_to_socket+0x6d>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a1 <write_line_to_socket+0x81>
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1150 <write_line_to_socket+0x30>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_line_to_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     115f <write_line_to_socket+0x3f>
mov    %eax,%ebx
xor    %ebp,%ebp
nopl   (%rax)
movslq %ebp,%rax
lea    (%r14,%rax,1),%rsi
mov    %ebx,%edx
sub    %eax,%edx
mov    %r15d,%edi
call   1030 <write@plt>
test   %eax,%eax
js     1163 <write_line_to_socket+0x43>
add    %eax,%ebp
cmp    %ebp,%ebx
jne    1140 <write_line_to_socket+0x20>
jmp    1165 <write_line_to_socket+0x45>
xor    %ebx,%ebx
jmp    1165 <write_line_to_socket+0x45>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_line_to_socket(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
br label %11
11: ; preds = %29, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %8
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = load i32, i32* %4
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i32, i32* %8
%22 = load i32, i32* %6
%23 = sub nsw i32 %21, %22
%24 = call i32 @write(i32 %16, i8* %20, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %15
%28 = load i32, i32* %7
store i32 %28, i32* %3
br label %35
29: ; preds = %15
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = add nsw i32 %31, %30
store i32 %32, i32* %6
br label %11
33: ; preds = %11
%34 = load i32, i32* %6
store i32 %34, i32* %3
br label %35
35: ; preds = %33, %27
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
define i32 @write_line_to_socket(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %2, %12
%6 = phi i32 [ %13, %12 ], [ 0, %2 ]
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = sub nsw i32 %3, %6
%10 = tail call i32 @write(i32 %0, i8* %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %5
%13 = add nsw i32 %10, %6
%14 = icmp eq i32 %3, %13
br i1 %14, label %15, label %5
15: ; preds = %5, %12, %2
%16 = phi i32 [ 0, %2 ], [ %3, %12 ], [ %10, %5 ]
ret i32 %16
}