#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*/ exit(int);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
int parse_msgstring(char *msgbuf, size_t msglen, char **str, size_t minlen) {
  if (*str || msglen < minlen)
    exit(1);
  *str = (char *)malloc(msglen + 1);
  memcpy(*str, msgbuf, msglen);
  (*str)[msglen] = 0;
  return 0;
}


x86 assembly (clang, -O0):
<parse_msgstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1164 <parse_msgstring+0x34>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    116e <parse_msgstring+0x3e>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_msgstring>:
push   %r15
push   %r14
push   %rbx
cmp    %rcx,%rsi
jb     1172 <parse_msgstring+0x42>
mov    %rdx,%r14
cmpq   $0x0,(%rdx)
jne    1172 <parse_msgstring+0x42>
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x1(%rsi),%rdi
call   1040 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
mov    (%r14),%rax
movb   $0x0,(%rax,%rbx,1)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
define i32 @parse_msgstring(i8* %0, i64 %1, i8** %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8**
%8 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8** %2, i8*** %7
store i64 %3, i64* %8
%9 = load i8**, i8*** %7
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %4
%13 = load i64, i64* %6
%14 = load i64, i64* %8
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %12, %4
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %12
%19 = load i64, i64* %6
%20 = add i64 %19, 1
%21 = call i64 @malloc(i64 %20)
%22 = inttoptr i64 %21 to i8*
%23 = load i8**, i8*** %7
store i8* %22, i8** %23
%24 = load i8**, i8*** %7
%25 = load i8*, i8** %24
%26 = load i8*, i8** %5
%27 = load i64, i64* %6
%28 = call i32 @memcpy(i8* %25, i8* %26, i64 %27)
%29 = load i8**, i8*** %7
%30 = load i8*, i8** %29
%31 = load i64, i64* %6
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8 0, i8* %32
ret i32 0
}

LLVM IR (-O2):
define i32 @parse_msgstring(i8* %0, i64 %1, i8** nocapture %2, i64 %3) {
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
%7 = icmp ult i64 %1, %3
%8 = or i1 %7, %6
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %4
%12 = add i64 %1, 1
%13 = tail call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %2
%15 = tail call i32 @memcpy(i8* %14, i8* %0, i64 %1)
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 %1
store i8 0, i8* %17
ret i32 0
}