#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 */
char *charesc(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int warterm_puts(char *s) {
  char buf[1024];
  strcpy(buf, "P\01");
  for (; *s; s++)
    strcat(buf, charesc(*s));
  strcat(buf, "\01");
  puts(buf);
  return 0;
}


x86 assembly (clang, -O0):
<warterm_puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a9 <warterm_puts+0x69>
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <charesc@plt>
mov    -0x418(%rbp),%rdi
mov    %rax,%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1162 <warterm_puts+0x22>
lea    -0x410(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x410(%rbp),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<warterm_puts>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbx
lea    0xeac(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcpy@plt>
mov    (%rbx),%al
test   %al,%al
je     118e <warterm_puts+0x4e>
add    $0x1,%rbx
mov    %rsp,%r14
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <charesc@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <strcat@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <warterm_puts+0x30>
lea    0xe6c(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"P\01\00"
@.str.1 = [2 x i8] c"\01\00"
define i32 @warterm_puts(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
store i8* %0, i8** %2
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %16, %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %6
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = call i8* @charesc(i8 signext %13)
%15 = call i32 @strcat(i8* %11, i8* %14)
br label %16
16: ; preds = %10
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %2
br label %6
19: ; preds = %6
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%21 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%23 = call i32 @puts(i8* %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"P\01\00"
@.str.1 = [2 x i8] c"\01\00"
define i32 @warterm_puts(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %1, %7
%8 = phi i8 [ %13, %7 ], [ %5, %1 ]
%9 = phi i8* [ %12, %7 ], [ %0, %1 ]
%10 = call i8* @charesc(i8 signext %8)
%11 = call i32 @strcat(i8* %3, i8* %10)
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %7
15: ; preds = %7, %1
%16 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @puts(i8* %3)
ret i32 0
}