#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 */
typedef int /*<<< orphan*/ str;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int parseAMsg(char *msg, char *buf, int *msgType) {
  int i;
  char str[256 + 1];
  for (i = 0; i < 4; i++)
    memset(&str[i], msg[i], 1);
  *msgType = atoi(str);
  memset(str, 0x00, sizeof(str));
  for (i = 0; i < strlen(msg); i++)
    memset(&str[i], msg[i + 4], 1);
  strcpy(buf, str);
  return 0;
}


x86 assembly (clang, -O0):
<parseAMsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    119c <parseAMsg+0x5c>
movslq -0x1c(%rbp),%rax
lea    -0x120(%rbp),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
movsbl %al,%esi
mov    $0x1,%edx
call   1050 <memset@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115e <parseAMsg+0x1e>
lea    -0x120(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1050 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x124(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x124(%rbp),%eax
cmp    %ecx,%eax
jge    1225 <parseAMsg+0xe5>
movslq -0x1c(%rbp),%rax
lea    -0x120(%rbp),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
movsbl %al,%esi
mov    $0x1,%edx
call   1050 <memset@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <parseAMsg+0x8a>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseAMsg>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r13
movsbl (%rdi),%esi
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x1,%edx
call   1050 <memset@plt>
lea    0x1(%rsp),%rdi
movsbl 0x1(%r13),%esi
mov    $0x1,%edx
call   1050 <memset@plt>
lea    0x2(%rsp),%rdi
movsbl 0x2(%r13),%esi
mov    $0x1,%edx
call   1050 <memset@plt>
lea    0x3(%rsp),%rdi
movsbl 0x3(%r13),%esi
mov    $0x1,%edx
call   1050 <memset@plt>
mov    %r12,%rdi
call   1060 <atoi@plt>
mov    %eax,(%r15)
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1050 <memset@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11f7 <parseAMsg+0xb7>
xor    %ebx,%ebx
lea    (%rsp,%rbx,1),%rdi
movsbl 0x4(%r13,%rbx,1),%esi
mov    $0x1,%edx
call   1050 <memset@plt>
add    $0x1,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     11d0 <parseAMsg+0x90>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @parseAMsg(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = alloca [257 x i8]
%5 = getelementptr inbounds [257 x i8], [257 x i8]* %4, i64 0, i64 0
%6 = load i8, i8* %0
%7 = call i32 @memset(i8* %5, i8 signext %6, i32 1)
%8 = getelementptr inbounds [257 x i8], [257 x i8]* %4, i64 0, i64 1
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = load i8, i8* %9
%11 = call i32 @memset(i8* %8, i8 signext %10, i32 1)
%12 = getelementptr inbounds [257 x i8], [257 x i8]* %4, i64 0, i64 2
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = load i8, i8* %13
%15 = call i32 @memset(i8* %12, i8 signext %14, i32 1)
%16 = getelementptr inbounds [257 x i8], [257 x i8]* %4, i64 0, i64 3
%17 = getelementptr inbounds i8, i8* %0, i64 3
%18 = load i8, i8* %17
%19 = call i32 @memset(i8* %16, i8 signext %18, i32 1)
%20 = call i32 @atoi(i8* %5)
store i32 %20, i32* %2
%21 = call i32 @memset(i8* %5, i8 signext 0, i32 257)
%22 = call i32 @strlen(i8* %0)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %3, %24
%25 = phi i64 [ %31, %24 ], [ 0, %3 ]
%26 = getelementptr inbounds [257 x i8], [257 x i8]* %4, i64 0, i64 %25
%27 = add nuw nsw i64 %25, 4
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @memset(i8* %26, i8 signext %29, i32 1)
%31 = add nuw nsw i64 %25, 1
%32 = call i32 @strlen(i8* %0)
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %24, label %35
35: ; preds = %24, %3
%36 = call i32 @strcpy(i8* %1, i8* %5)
ret i32 0
}