#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 /*<<< orphan*/ watermark_putchar(void *, int, int, int, int, char);
void watermark_putstring(void *ptr, int width, int height, int x, int y,
                         char *str) {
  int curx = x;
  int cury = y;
  while (*str) {
    if (*str == '\n') {
      cury += 48 + 12;
      curx = x;
    } else {
      watermark_putchar(ptr, width, height, curx, cury, *str);
      curx += 25 + 5;
    }
    str++;
  }
}


x86 assembly (clang, -O0):
<watermark_putstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a2 <watermark_putstring+0x92>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    116a <watermark_putstring+0x5a>
mov    -0x28(%rbp),%eax
add    $0x3c,%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1191 <watermark_putstring+0x81>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x20(%rbp),%rax
movsbl (%rax),%r9d
call   1030 <watermark_putchar@plt>
mov    -0x24(%rbp),%eax
add    $0x1e,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1139 <watermark_putstring+0x29>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<watermark_putstring>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %r8d,%ebp
mov    %ecx,%r15d
mov    %edx,0x4(%rsp)
mov    %esi,%r12d
mov    %rdi,%r13
mov    %ecx,%r14d
jmp    114a <watermark_putstring+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x3c,%ebp
add    $0x1,%rbx
mov    %r15d,%r14d
movzbl (%rbx),%eax
cmp    $0xa,%al
je     1140 <watermark_putstring+0x30>
test   %al,%al
je     1178 <watermark_putstring+0x68>
movsbl %al,%r9d
mov    %r13,%rdi
mov    %r12d,%esi
mov    0x4(%rsp),%edx
mov    %r14d,%ecx
mov    %ebp,%r8d
call   1030 <watermark_putchar@plt>
add    $0x1e,%r14d
add    $0x1,%rbx
jmp    114a <watermark_putstring+0x3a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @watermark_putstring(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i8* %5, i8** %12
%15 = load i32, i32* %10
store i32 %15, i32* %13
%16 = load i32, i32* %11
store i32 %16, i32* %14
br label %17
17: ; preds = %41, %6
%18 = load i8*, i8** %12
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %44
21: ; preds = %17
%22 = load i8*, i8** %12
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* %14
%28 = add nsw i32 %27, 60
store i32 %28, i32* %14
%29 = load i32, i32* %10
store i32 %29, i32* %13
br label %41
30: ; preds = %21
%31 = load i8*, i8** %7
%32 = load i32, i32* %8
%33 = load i32, i32* %9
%34 = load i32, i32* %13
%35 = load i32, i32* %14
%36 = load i8*, i8** %12
%37 = load i8, i8* %36
%38 = call i32 @watermark_putchar(i8* %31, i32 %32, i32 %33, i32 %34, i32 %35, i8 signext %37)
%39 = load i32, i32* %13
%40 = add nsw i32 %39, 30
store i32 %40, i32* %13
br label %41
41: ; preds = %30, %26
%42 = load i8*, i8** %12
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %12
br label %17
44: ; preds = %17
ret void
}

LLVM IR (-O2):
define void @watermark_putstring(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i8* nocapture %5) {
br label %7
7: ; preds = %17, %6
%8 = phi i8* [ %5, %6 ], [ %20, %17 ]
%9 = phi i32 [ %3, %6 ], [ %18, %17 ]
%10 = phi i32 [ %4, %6 ], [ %19, %17 ]
%11 = load i8, i8* %8
switch i8 %11, label %14 [
i8 0, label %21
i8 10, label %12
]
12: ; preds = %7
%13 = add nsw i32 %10, 60
br label %17
14: ; preds = %7
%15 = tail call i32 @watermark_putchar(i8* %0, i32 %1, i32 %2, i32 %9, i32 %10, i8 signext %11)
%16 = add nsw i32 %9, 30
br label %17
17: ; preds = %14, %12
%18 = phi i32 [ %3, %12 ], [ %16, %14 ]
%19 = phi i32 [ %13, %12 ], [ %10, %14 ]
%20 = getelementptr inbounds i8, i8* %8, i64 1
br label %7
21: ; preds = %7
ret void
}