#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*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(unsigned char *, char const *, size_t);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
int /*<<< orphan*/ write_msg(int, unsigned char *, int);
void do_status_msg(int tty_fd, const char *msg) {
  unsigned char buf[34];
  size_t msg_len;
  msg_len = strlen(msg);
  if (msg_len > 33) {
    fputs("Message too long\n", stderr);
    return;
  }
  memset(buf, 0, sizeof buf);
  buf[0] = 0x19;
  memcpy(buf + 1, msg, msg_len);
  write_msg(tty_fd, buf, sizeof buf);
}


x86 assembly (clang, -O0):
<do_status_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x21,-0x48(%rbp)
jbe    1191 <do_status_msg+0x41>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
call   1040 <fputs@plt>
jmp    11cb <do_status_msg+0x7b>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x22,%edx
call   1050 <memset@plt>
movb   $0x19,-0x40(%rbp)
lea    -0x40(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x22,%edx
call   1070 <write_msg@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_status_msg>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    $0x22,%rax
jb     118d <do_status_msg+0x3d>
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe82(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fputs@plt>
mov    %rax,%rbp
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x22,%edx
call   1050 <memset@plt>
movb   $0x19,(%rsp)
lea    0x1(%rsp),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1060 <memcpy@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x22,%edx
call   1070 <write_msg@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Message too long\0A\00"
@stderr = global i32 0
define void @do_status_msg(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [34 x i8]
%6 = alloca i64
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp ugt i64 %9, 33
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fputs(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %26
14: ; preds = %2
%15 = getelementptr inbounds [34 x i8], [34 x i8]* %5, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 34)
%17 = getelementptr inbounds [34 x i8], [34 x i8]* %5, i64 0, i64 0
store i8 25, i8* %17
%18 = getelementptr inbounds [34 x i8], [34 x i8]* %5, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8*, i8** %4
%21 = load i64, i64* %6
%22 = call i32 @memcpy(i8* %19, i8* %20, i64 %21)
%23 = load i32, i32* %3
%24 = getelementptr inbounds [34 x i8], [34 x i8]* %5, i64 0, i64 0
%25 = call i32 @write_msg(i32 %23, i8* %24, i32 34)
br label %26
26: ; preds = %14, %11
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"Message too long\0A\00"
@stderr = global i32 0
define void @do_status_msg(i32 %0, i8* %1) {
%3 = alloca [34 x i8]
%4 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = icmp ugt i64 %5, 33
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fputs(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %15
10: ; preds = %2
%11 = call i32 @memset(i8* %4, i32 0, i32 34)
store i8 25, i8* %4
%12 = getelementptr inbounds [34 x i8], [34 x i8]* %3, i64 0, i64 1
%13 = call i32 @memcpy(i8* %12, i8* %1, i64 %5)
%14 = call i32 @write_msg(i32 %0, i8* %4, i32 34)
br label %15
15: ; preds = %10, %7
ret void
}