#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*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
void sendCW(int fd, char *text) {
  char cwCmd[29];
  char buffer[25];
  int len = strlen(text);
  while (len > 0) {
    if (len <= 24) {
      strcpy(buffer, text);
      len = 0;
    } else {
      strncpy(buffer, text, 24);
      buffer[24] = '\0';
      text += 24;
      len -= 24;
    }
    sprintf(cwCmd, "KY %s;", buffer);
    write(fd, cwCmd, strlen(cwCmd));
    usleep(100e3);
  }
}


x86 assembly (clang, -O0):
<sendCW>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jle    121b <sendCW+0xbb>
cmpl   $0x18,-0x54(%rbp)
jg     11a8 <sendCW+0x48>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x54(%rbp)
jmp    11d3 <sendCW+0x73>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x18,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x10(%rbp)
mov    -0x54(%rbp),%eax
sub    $0x18,%eax
mov    %eax,-0x54(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe1e(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x64(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
jmp    117b <sendCW+0x1b>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendCW>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    11fb <sendCW+0x9b>
mov    %eax,%ebp
mov    %rsp,%r15
lea    0xe74(%rip),%r12
lea    0x20(%rsp),%r13
jmp    11e7 <sendCW+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x18,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x18(%rsp)
add    $0x18,%rbx
add    $0xffffffe8,%ebp
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1070 <sprintf@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
test   %ebp,%ebp
jle    11fb <sendCW+0x9b>
mov    %r15,%rdi
mov    %rbx,%rsi
cmp    $0x18,%ebp
ja     11a0 <sendCW+0x40>
call   1040 <strcpy@plt>
xor    %ebp,%ebp
jmp    11b6 <sendCW+0x56>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"KY %s;\00"
define void @sendCW(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [29 x i8]
%6 = alloca [25 x i8]
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
br label %10
10: ; preds = %29, %2
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %39
13: ; preds = %10
%14 = load i32, i32* %7
%15 = icmp sle i32 %14, 24
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = getelementptr inbounds [25 x i8], [25 x i8]* %6, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = call i32 @strcpy(i8* %17, i8* %18)
store i32 0, i32* %7
br label %29
20: ; preds = %13
%21 = getelementptr inbounds [25 x i8], [25 x i8]* %6, i64 0, i64 0
%22 = load i8*, i8** %4
%23 = call i32 @strncpy(i8* %21, i8* %22, i32 24)
%24 = getelementptr inbounds [25 x i8], [25 x i8]* %6, i64 0, i64 24
store i8 0, i8* %24
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 24
store i8* %26, i8** %4
%27 = load i32, i32* %7
%28 = sub nsw i32 %27, 24
store i32 %28, i32* %7
br label %29
29: ; preds = %20, %16
%30 = getelementptr inbounds [29 x i8], [29 x i8]* %5, i64 0, i64 0
%31 = getelementptr inbounds [25 x i8], [25 x i8]* %6, i64 0, i64 0
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = load i32, i32* %3
%34 = getelementptr inbounds [29 x i8], [29 x i8]* %5, i64 0, i64 0
%35 = getelementptr inbounds [29 x i8], [29 x i8]* %5, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = call i32 @write(i32 %33, i8* %34, i32 %36)
%38 = call i32 @usleep(i32 100000)
br label %10
39: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"KY %s;\00"
define void @sendCW(i32 %0, i8* %1) {
%3 = alloca [29 x i8]
%4 = alloca [25 x i8]
%5 = getelementptr inbounds [29 x i8], [29 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %2
%10 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 24
br label %11
11: ; preds = %9, %21
%12 = phi i32 [ %7, %9 ], [ %23, %21 ]
%13 = phi i8* [ %1, %9 ], [ %22, %21 ]
%14 = icmp ult i32 %12, 25
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @strcpy(i8* %6, i8* %13)
br label %21
17: ; preds = %11
%18 = call i32 @strncpy(i8* %6, i8* %13, i32 24)
store i8 0, i8* %10
%19 = getelementptr inbounds i8, i8* %13, i64 24
%20 = add nsw i32 %12, -24
br label %21
21: ; preds = %17, %15
%22 = phi i8* [ %13, %15 ], [ %19, %17 ]
%23 = phi i32 [ 0, %15 ], [ %20, %17 ]
%24 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %6)
%25 = call i32 @strlen(i8* %5)
%26 = call i32 @write(i32 %0, i8* %5, i32 %25)
%27 = call i32 @usleep(i32 100000)
%28 = icmp sgt i32 %23, 0
br i1 %28, label %11, label %29
29: ; preds = %21, %2
ret void
}