#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 */
struct stream {
  int dummy;
};

/* Variables and functions */
int stream_write(struct stream *, char *, int);
int rcsdelta_writestring(char *textline, size_t size, struct stream *dest) {
  char buf[3];
  size_t i;
  int count;
  for (i = 0; i < size; i++) {
    buf[0] = textline[i];
    buf[1] = '\0';
    count = 1;
    if (buf[0] == '@') {
      buf[1] = '@';
      buf[2] = '\0';
      count = 2;
    }
    if (stream_write(dest, buf, count) == -1)
      return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<rcsdelta_writestring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11aa <rcsdelta_writestring+0x9a>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x23(%rbp)
movb   $0x0,-0x22(%rbp)
movl   $0x1,-0x34(%rbp)
movsbl -0x23(%rbp),%eax
cmp    $0x40,%eax
jne    116f <rcsdelta_writestring+0x5f>
movb   $0x40,-0x22(%rbp)
movb   $0x0,-0x21(%rbp)
movl   $0x2,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x23(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <stream_write@plt>
cmp    $0xffffffff,%eax
jne    1194 <rcsdelta_writestring+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <rcsdelta_writestring+0xa1>
jmp    1199 <rcsdelta_writestring+0x89>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    112c <rcsdelta_writestring+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rcsdelta_writestring>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rsi,%rsi
je     117c <rcsdelta_writestring+0x6c>
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
xor    %ebx,%ebx
lea    0xd(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r15,%rbx,1),%eax
mov    %al,0xd(%rsp)
movb   $0x0,0xe(%rsp)
mov    $0x1,%edx
cmp    $0x40,%al
jne    1163 <rcsdelta_writestring+0x53>
movw   $0x40,0xe(%rsp)
mov    $0x2,%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <stream_write@plt>
cmp    $0xffffffff,%eax
je     1180 <rcsdelta_writestring+0x70>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1140 <rcsdelta_writestring+0x30>
xor    %eax,%eax
jmp    1185 <rcsdelta_writestring+0x75>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stream = type { i32 }
define i32 @rcsdelta_writestring(i8* %0, i64 %1, %struct.stream* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.stream*
%8 = alloca [3 x i8]
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store %struct.stream* %2, %struct.stream** %7
store i64 0, i64* %9
br label %11
11: ; preds = %37, %3
%12 = load i64, i64* %9
%13 = load i64, i64* %6
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %40
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i64, i64* %9
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
store i8 %19, i8* %20
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
store i8 0, i8* %21
store i32 1, i32* %10
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 64
br i1 %25, label %26, label %29
26: ; preds = %15
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
store i8 64, i8* %27
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 2
store i8 0, i8* %28
store i32 2, i32* %10
br label %29
29: ; preds = %26, %15
%30 = load %struct.stream*, %struct.stream** %7
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%32 = load i32, i32* %10
%33 = call i32 @stream_write(%struct.stream* %30, i8* %31, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 -1, i32* %4
br label %41
36: ; preds = %29
br label %37
37: ; preds = %36
%38 = load i64, i64* %9
%39 = add i64 %38, 1
store i64 %39, i64* %9
br label %11
40: ; preds = %11
store i32 0, i32* %4
br label %41
41: ; preds = %40, %35
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
%struct.stream = type { i32 }
define i32 @rcsdelta_writestring(i8* nocapture %0, i64 %1, %struct.stream* %2) {
%4 = alloca [3 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%6 = icmp eq i64 %1, 0
br i1 %6, label %23, label %7
7: ; preds = %3
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
br label %12
10: ; preds = %18
%11 = icmp eq i64 %22, %1
br i1 %11, label %23, label %12
12: ; preds = %7, %10
%13 = phi i64 [ 0, %7 ], [ %22, %10 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
store i8 %15, i8* %5
store i8 0, i8* %8
%16 = icmp eq i8 %15, 64
br i1 %16, label %17, label %18
17: ; preds = %12
store i8 64, i8* %8
store i8 0, i8* %9
br label %18
18: ; preds = %17, %12
%19 = phi i32 [ 2, %17 ], [ 1, %12 ]
%20 = call i32 @stream_write(%struct.stream* %2, i8* %5, i32 %19)
%21 = icmp eq i32 %20, -1
%22 = add nuw i64 %13, 1
br i1 %21, label %23, label %10
23: ; preds = %18, %10, %3
%24 = phi i32 [ 0, %3 ], [ 0, %10 ], [ -1, %18 ]
ret i32 %24
}