#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 */
unsigned char strlen(char *);
int /*<<< orphan*/ write(int, char *, unsigned char);
int TUI_OutBlock(int fp, char *pSearch, char *phraseOut) {
  int n = 0;
  unsigned char l = strlen(pSearch);
  unsigned char str;
  write(fp, (char *)&l, 1);
  n++;
  if (l > 2) {
    write(fp, (char *)(pSearch + 2), (l - 2));
    n += (l - 2);
  }
  str = strlen(phraseOut);
  write(fp, (char *)&str, 1);
  n++;
  write(fp, (char *)phraseOut, str);
  n += str;
  return n;
}


x86 assembly (clang, -O0):
<TUI_OutBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %al,-0x1d(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movzbl -0x1d(%rbp),%eax
cmp    $0x2,%eax
jle    1194 <TUI_OutBlock+0x74>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    $0x2,%rsi
movzbl -0x1d(%rbp),%eax
sub    $0x2,%eax
movzbl %al,%edx
call   1030 <write@plt>
movzbl -0x1d(%rbp),%eax
sub    $0x2,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %al,-0x1e(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1e(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
movzbl -0x1e(%rbp),%edx
call   1030 <write@plt>
movzbl -0x1e(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TUI_OutBlock>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%r15d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %al,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x2,%ebp
cmp    $0x3,%bl
jb     1177 <TUI_OutBlock+0x57>
add    $0x2,%r12
lea    -0x2(%rbx),%eax
movzbl %al,%edx
mov    %r15d,%edi
mov    %r12,%rsi
call   1030 <write@plt>
movzbl %bl,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %al,0xe(%rsp)
lea    0xe(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1030 <write@plt>
movzbl %bl,%ebx
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
add    %ebx,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @TUI_OutBlock(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%10 = load i8*, i8** %5
%11 = call zeroext i8 @strlen(i8* %10)
store i8 %11, i8* %8
%12 = load i32, i32* %4
%13 = call i32 @write(i32 %12, i8* %8, i8 zeroext 1)
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 1
store i32 %15, i32* %7
%16 = load i8, i8* %8
%17 = zext i8 %16 to i32
%18 = icmp sgt i32 %17, 2
br i1 %18, label %19, label %33
19: ; preds = %3
%20 = load i32, i32* %4
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = load i8, i8* %8
%24 = zext i8 %23 to i32
%25 = sub nsw i32 %24, 2
%26 = trunc i32 %25 to i8
%27 = call i32 @write(i32 %20, i8* %22, i8 zeroext %26)
%28 = load i8, i8* %8
%29 = zext i8 %28 to i32
%30 = sub nsw i32 %29, 2
%31 = load i32, i32* %7
%32 = add nsw i32 %31, %30
store i32 %32, i32* %7
br label %33
33: ; preds = %19, %3
%34 = load i8*, i8** %6
%35 = call zeroext i8 @strlen(i8* %34)
store i8 %35, i8* %9
%36 = load i32, i32* %4
%37 = call i32 @write(i32 %36, i8* %9, i8 zeroext 1)
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
%40 = load i32, i32* %4
%41 = load i8*, i8** %6
%42 = load i8, i8* %9
%43 = call i32 @write(i32 %40, i8* %41, i8 zeroext %42)
%44 = load i8, i8* %9
%45 = zext i8 %44 to i32
%46 = load i32, i32* %7
%47 = add nsw i32 %46, %45
store i32 %47, i32* %7
%48 = load i32, i32* %7
ret i32 %48
}

LLVM IR (-O2):
define i32 @TUI_OutBlock(i32 %0, i8* %1, i8* %2) {
%4 = alloca i8
%5 = alloca i8
%6 = tail call zeroext i8 @strlen(i8* %1)
store i8 %6, i8* %4
%7 = call i32 @write(i32 %0, i8* %4, i8 zeroext 1)
%8 = icmp ugt i8 %6, 2
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = getelementptr inbounds i8, i8* %1, i64 2
%11 = add i8 %6, -2
%12 = tail call i32 @write(i32 %0, i8* %10, i8 zeroext %11)
%13 = zext i8 %6 to i32
br label %14
14: ; preds = %9, %3
%15 = phi i32 [ %13, %9 ], [ 2, %3 ]
%16 = tail call zeroext i8 @strlen(i8* %2)
store i8 %16, i8* %5
%17 = call i32 @write(i32 %0, i8* %5, i8 zeroext 1)
%18 = tail call i32 @write(i32 %0, i8* %2, i8 zeroext %16)
%19 = zext i8 %16 to i32
%20 = add nuw nsw i32 %15, %19
ret i32 %20
}