#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
void new_message(char *buf, char **msg_array, int msg_count) {
  char *first_msg = msg_array[0];
  for (int i = 0; i < msg_count - 1; i++) {
    msg_array[i] = msg_array[i + 1];
  }
  msg_array[msg_count - 1] = first_msg;
  memset(msg_array[msg_count - 1], '\0', 40);
  memcpy(msg_array[msg_count - 1], buf, 40);
}


x86 assembly (clang, -O0):
<new_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1181 <new_message+0x61>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1145 <new_message+0x25>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_message>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%r15
lea    -0x1(%rdx),%ebp
cmp    $0x2,%edx
jl     115a <new_message+0x2a>
lea    0x8(%rbx),%rsi
mov    %ebp,%edx
shl    $0x3,%rdx
mov    %rbx,%rdi
call   1050 <memmove@plt>
movslq %ebp,%rbp
mov    %r15,(%rbx,%rbp,8)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    (%rbx,%rbp,8),%rdi
mov    %r14,%rsi
mov    $0x28,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <memcpy@plt>

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

LLVM IR (-O2):
define void @new_message(i8* %0, i8** nocapture %1, i32 %2) {
%4 = load i8*, i8** %1
%5 = add i32 %2, -1
%6 = icmp sgt i32 %2, 1
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = bitcast i8** %1 to i8*
%9 = getelementptr i8*, i8** %1, i64 1
%10 = bitcast i8** %9 to i8*
%11 = zext i32 %5 to i64
%12 = shl nuw nsw i64 %11, 3
br label %13
13: ; preds = %7, %3
%14 = sext i32 %5 to i64
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
store i8* %4, i8** %15
%16 = tail call i32 @memset(i8* %4, i8 signext 0, i32 40)
%17 = load i8*, i8** %15
%18 = tail call i32 @memcpy(i8* %17, i8* %0, i32 40)
ret void
}