#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
void testmalloc() {
  char *c[100];
  for (int i = 0; i < 10; i++) {
    c[i] = (char *)malloc(2048);
    strcpy(c[i], "shashi");
    printf("%s i=%d \n", c[i], i);
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<testmalloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
movl   $0x0,-0x324(%rbp)
cmpl   $0xa,-0x324(%rbp)
jge    11c0 <testmalloc+0x90>
mov    $0x800,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
movslq -0x324(%rbp),%rax
mov    %rcx,-0x320(%rbp,%rax,8)
ff
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rdi
ff
lea    0xe7c(%rip),%rsi
call   1030 <strcpy@plt>
movslq -0x324(%rbp),%rax
mov    -0x320(%rbp,%rax,8),%rsi
ff
mov    -0x324(%rbp),%edx
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x324(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x324(%rbp)
jmp    1145 <testmalloc+0x15>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testmalloc>:
push   %r15
push   %r14
push   %rbx
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xea7(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe9c(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x7,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x9,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd14(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"shashi\00"
@.str.1 = [10 x i8] c"%s i=%d \0A\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
define void @testmalloc() {
%1 = alloca [100 x i8*]
%2 = alloca i32
store i32 0, i32* %2
br label %3
3: ; preds = %23, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 10
br i1 %5, label %6, label %26
6: ; preds = %3
%7 = call i64 @malloc(i32 2048)
%8 = inttoptr i64 %7 to i8*
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %10
store i8* %8, i8** %11
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %13
%15 = load i8*, i8** %14
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i8*], [100 x i8*]* %1, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = load i32, i32* %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21)
br label %23
23: ; preds = %6
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %3
26: ; preds = %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"shashi\00"
@.str.1 = [10 x i8] c"%s i=%d \0A\00"
@str = [2 x i8] c"\0A\00"
define void @testmalloc() {
%1 = tail call i64 @malloc(i32 2048)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 0)
%5 = tail call i64 @malloc(i32 2048)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 1)
%9 = tail call i64 @malloc(i32 2048)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 2)
%13 = tail call i64 @malloc(i32 2048)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 3)
%17 = tail call i64 @malloc(i32 2048)
%18 = inttoptr i64 %17 to i8*
%19 = tail call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 4)
%21 = tail call i64 @malloc(i32 2048)
%22 = inttoptr i64 %21 to i8*
%23 = tail call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 5)
%25 = tail call i64 @malloc(i32 2048)
%26 = inttoptr i64 %25 to i8*
%27 = tail call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 6)
%29 = tail call i64 @malloc(i32 2048)
%30 = inttoptr i64 %29 to i8*
%31 = tail call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %30, i32 7)
%33 = tail call i64 @malloc(i32 2048)
%34 = inttoptr i64 %33 to i8*
%35 = tail call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %34, i32 8)
%37 = tail call i64 @malloc(i32 2048)
%38 = inttoptr i64 %37 to i8*
%39 = tail call i32 @strcpy(i8* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %38, i32 9)
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}