#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(char *, char const *, size_t);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
int /*<<< orphan*/ write_msg(int, char *, size_t);
void do_setlogo(int tty_fd, const char *logo) {
  char msg_buf[255];
  size_t logo_len = strlen(logo);
  if (logo_len > sizeof msg_buf - 1) {
    fputs("Logo too long\n", stderr);
    return;
  }
  msg_buf[0] = 0x11;
  memcpy(msg_buf + 1, logo, logo_len);
  write_msg(tty_fd, msg_buf, logo_len + 1);
}


x86 assembly (clang, -O0):
<do_setlogo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0xfe,-0x118(%rbp)
jbe    118d <do_setlogo+0x4d>
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1040 <fputs@plt>
jmp    11c9 <do_setlogo+0x89>
movb   $0x11,-0x110(%rbp)
lea    -0x110(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x118(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x118(%rbp),%rdx
add    $0x1,%rdx
call   1060 <write_msg@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_setlogo>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    $0xff,%rax
jb     1181 <do_setlogo+0x41>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fputs@plt>
mov    %rax,%rbx
movb   $0x11,(%rsp)
lea    0x1(%rsp),%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1050 <memcpy@plt>
add    $0x1,%rbx
mov    %rsp,%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
call   1060 <write_msg@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"Logo too long\0A\00"
@stderr = global i32 0
define void @do_setlogo(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [255 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, 254
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %26
14: ; preds = %2
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
store i8 17, i8* %15
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8*, i8** %4
%19 = load i64, i64* %6
%20 = call i32 @memcpy(i8* %17, i8* %18, i64 %19)
%21 = load i32, i32* %3
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%23 = load i64, i64* %6
%24 = add i64 %23, 1
%25 = call i32 @write_msg(i32 %21, i8* %22, i64 %24)
br label %26
26: ; preds = %14, %11
ret void
}

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