#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void readmsgHTTP(char *msg, char **request) {
  int i = 0, j = 0, k = 0;
  char buffer[3000];
  memset(buffer, 0, 3000);
  printf("\n******HTTP Request******\n%s************************\n", msg);
  for (i = 0; i < 3000; i++) {
    buffer[k] = msg[i];
    k++;
    if (msg[i] == '\n') {
      if (k == 1)
        buffer[k - 1] = '\0';
      else
        buffer[k - 2] = '\0';
      strcpy(request[j], buffer);
      j++;
      memset(buffer, 0, 3000);
      k = 0;
    }
  }
}


x86 assembly (clang, -O0):
<readmsgHTTP>:
push   %rbp
mov    %rsp,%rbp
sub    $0xbe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0xbe0(%rbp),%rdi
xor    %esi,%esi
mov    $0xbb8,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rsi
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xbb8,-0x14(%rbp)
jge    1240 <readmsgHTTP+0x110>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0xbe0(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    122d <readmsgHTTP+0xfd>
cmpl   $0x1,-0x1c(%rbp)
jne    11e2 <readmsgHTTP+0xb2>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0xbe0(%rbp,%rax,1)
jmp    11f2 <readmsgHTTP+0xc2>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0x0,-0xbe0(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0xbe0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
lea    -0xbe0(%rbp),%rdi
xor    %esi,%esi
mov    $0xbb8,%edx
call   1050 <memset@plt>
movl   $0x0,-0x1c(%rbp)
jmp    1232 <readmsgHTTP+0x102>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <readmsgHTTP+0x52>
add    $0xbe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readmsgHTTP>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xbb8,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsp,%r15
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xbb8,%edx
call   1050 <memset@plt>
lea    0xe9e(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    11c5 <readmsgHTTP+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %rsp,%rax
sub    $0x1,%ebp
movslq %ebp,%rcx
lea    (%rsp,%rcx,1),%rcx
cmovb  %rax,%rcx
movb   $0x0,(%rcx)
movslq %r13d,%r13
mov    (%r14,%r13,8),%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
add    $0x1,%r13d
xor    %ebp,%ebp
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xbb8,%edx
call   1050 <memset@plt>
add    $0x1,%rbx
cmp    $0xbb8,%rbx
je     11da <readmsgHTTP+0xaa>
movzbl (%r12,%rbx,1),%ecx
movslq %ebp,%rax
mov    %cl,(%rsp,%rax,1)
cmp    $0xa,%cl
je     1180 <readmsgHTTP+0x50>
add    $0x1,%ebp
jmp    11b8 <readmsgHTTP+0x88>
add    $0xbb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"\0A******HTTP Request******\0A%s************************\0A\00"
define void @readmsgHTTP(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3000 x i8]
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = getelementptr inbounds [3000 x i8], [3000 x i8]* %8, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 3000)
%11 = load i8*, i8** %3
%12 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 0, i32* %5
br label %13
13: ; preds = %60, %2
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 3000
br i1 %15, label %16, label %63
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [3000 x i8], [3000 x i8]* %8, i64 0, i64 %23
store i8 %21, i8* %24
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
%27 = load i8*, i8** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 10
br i1 %33, label %34, label %59
34: ; preds = %16
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i32, i32* %7
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [3000 x i8], [3000 x i8]* %8, i64 0, i64 %40
store i8 0, i8* %41
br label %47
42: ; preds = %34
%43 = load i32, i32* %7
%44 = sub nsw i32 %43, 2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [3000 x i8], [3000 x i8]* %8, i64 0, i64 %45
store i8 0, i8* %46
br label %47
47: ; preds = %42, %37
%48 = load i8**, i8*** %4
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = getelementptr inbounds [3000 x i8], [3000 x i8]* %8, i64 0, i64 0
%54 = call i32 @strcpy(i8* %52, i8* %53)
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
%57 = getelementptr inbounds [3000 x i8], [3000 x i8]* %8, i64 0, i64 0
%58 = call i32 @memset(i8* %57, i32 0, i32 3000)
store i32 0, i32* %7
br label %59
59: ; preds = %47, %16
br label %60
60: ; preds = %59
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %13
63: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [54 x i8] c"\0A******HTTP Request******\0A%s************************\0A\00"
define void @readmsgHTTP(i8* %0, i8** nocapture %1) {
%3 = alloca [3000 x i8]
%4 = getelementptr inbounds [3000 x i8], [3000 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 3000)
%6 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %2, %29
%8 = phi i64 [ 0, %2 ], [ %32, %29 ]
%9 = phi i32 [ 0, %2 ], [ %31, %29 ]
%10 = phi i32 [ 0, %2 ], [ %30, %29 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %8
%12 = load i8, i8* %11
%13 = sext i32 %9 to i64
%14 = getelementptr inbounds [3000 x i8], [3000 x i8]* %3, i64 0, i64 %13
store i8 %12, i8* %14
%15 = add nsw i32 %9, 1
%16 = icmp eq i8 %12, 10
br i1 %16, label %17, label %29
17: ; preds = %7
%18 = icmp eq i32 %9, 0
%19 = add nsw i32 %9, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [3000 x i8], [3000 x i8]* %3, i64 0, i64 %20
%22 = select i1 %18, i8* %14, i8* %21
store i8 0, i8* %22
%23 = sext i32 %10 to i64
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @strcpy(i8* %25, i8* %4)
%27 = add nsw i32 %10, 1
%28 = call i32 @memset(i8* %4, i32 0, i32 3000)
br label %29
29: ; preds = %7, %17
%30 = phi i32 [ %27, %17 ], [ %10, %7 ]
%31 = phi i32 [ 0, %17 ], [ %15, %7 ]
%32 = add nuw nsw i64 %8, 1
%33 = icmp eq i64 %32, 3000
br i1 %33, label %34, label %7
34: ; preds = %29
ret void
}