#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 */
size_t encode(char *, size_t, char *);
size_t read(int, char **, int);
int /*<<< orphan*/ write(int, char *, size_t);
void encodefd(int fdin, int fdout) {
  while (1) {
    char in[54], out[73];
    size_t inlen = read(fdin, &in, sizeof in);
    if (inlen == 0)
      break;
    size_t outlen = encode(in, inlen, out);
    out[outlen++] = '\n';
    write(fdout, out, outlen);
  }
}


x86 assembly (clang, -O0):
<encodefd>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x36,%edx
call   1050 <read@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    116c <encodefd+0x3c>
jmp    11c2 <encodefd+0x92>
lea    -0x40(%rbp),%rdi
mov    -0x98(%rbp),%rsi
lea    -0x90(%rbp),%rdx
call   1030 <encode@plt>
mov    %rax,-0xa0(%rbp)
mov    -0xa0(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xa0(%rbp)
movb   $0xa,-0x90(%rbp,%rax,1)
0a
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    -0xa0(%rbp),%rdx
call   1040 <write@plt>
jmp    1141 <encodefd+0x11>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encodefd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
mov    %rsp,%rsi
mov    $0x36,%edx
call   1050 <read@plt>
test   %rax,%rax
je     1197 <encodefd+0x67>
mov    %rsp,%rbx
lea    0x40(%rsp),%rbp
nopl   (%rax)
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %rbp,%rdx
call   1030 <encode@plt>
movb   $0xa,0x40(%rsp,%rax,1)
lea    0x1(%rax),%rdx
mov    %r14d,%edi
mov    %rbp,%rsi
call   1040 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x36,%edx
call   1050 <read@plt>
test   %rax,%rax
jne    1160 <encodefd+0x30>
add    $0x98,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @encodefd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [54 x i8]
%6 = alloca [73 x i8]
%7 = alloca i64
%8 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %9
9: ; preds = %2, %16
%10 = load i32, i32* %3
%11 = bitcast [54 x i8]* %5 to i8**
%12 = call i64 @read(i32 %10, i8** %11, i32 54)
store i64 %12, i64* %7
%13 = load i64, i64* %7
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
br label %28
16: ; preds = %9
%17 = getelementptr inbounds [54 x i8], [54 x i8]* %5, i64 0, i64 0
%18 = load i64, i64* %7
%19 = getelementptr inbounds [73 x i8], [73 x i8]* %6, i64 0, i64 0
%20 = call i64 @encode(i8* %17, i64 %18, i8* %19)
store i64 %20, i64* %8
%21 = load i64, i64* %8
%22 = add i64 %21, 1
store i64 %22, i64* %8
%23 = getelementptr inbounds [73 x i8], [73 x i8]* %6, i64 0, i64 %21
store i8 10, i8* %23
%24 = load i32, i32* %4
%25 = getelementptr inbounds [73 x i8], [73 x i8]* %6, i64 0, i64 0
%26 = load i64, i64* %8
%27 = call i32 @write(i32 %24, i8* %25, i64 %26)
br label %9
28: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @encodefd(i32 %0, i32 %1) {
%3 = alloca [54 x i8]
%4 = alloca [73 x i8]
%5 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [73 x i8], [73 x i8]* %4, i64 0, i64 0
%7 = bitcast [54 x i8]* %3 to i8**
%8 = call i64 @read(i32 %0, i8** %7, i32 54)
%9 = icmp eq i64 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %2, %10
%11 = phi i64 [ %16, %10 ], [ %8, %2 ]
%12 = call i64 @encode(i8* %5, i64 %11, i8* %6)
%13 = add i64 %12, 1
%14 = getelementptr inbounds [73 x i8], [73 x i8]* %4, i64 0, i64 %12
store i8 10, i8* %14
%15 = call i32 @write(i32 %1, i8* %6, i64 %13)
%16 = call i64 @read(i32 %0, i8** %7, i32 54)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %10, %2
ret void
}