#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 */
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *DupNString(int n, char *str) {
  int nSize = strlen(str);
  char *res = malloc(n * nSize + 1);
  int i;
  *res = 0;
  for (i = 0; i < n; i++)
    strcat(res, str);
  return res;
}


x86 assembly (clang, -O0):
<DupNString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
imul   -0x14(%rbp),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1193 <DupNString+0x63>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116c <DupNString+0x3c>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DupNString>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsi,%rdi
call   1030 <strlen@plt>
imul   %ebp,%eax
lea    0x1(%rax),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
test   %ebp,%ebp
jle    1170 <DupNString+0x40>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
add    $0xffffffff,%ebp
jne    1160 <DupNString+0x30>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @DupNString(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %3
%11 = load i32, i32* %5
%12 = mul nsw i32 %10, %11
%13 = add nsw i32 %12, 1
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
store i8 0, i8* %15
store i32 0, i32* %7
br label %16
16: ; preds = %24, %2
%17 = load i32, i32* %7
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = load i8*, i8** %4
%23 = call i32 @strcat(i8* %21, i8* %22)
br label %24
24: ; preds = %20
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %16
27: ; preds = %16
%28 = load i8*, i8** %6
ret i8* %28
}

LLVM IR (-O2):
define i8* @DupNString(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = mul nsw i32 %3, %0
%5 = add nsw i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
store i8 0, i8* %6
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %13
8: ; preds = %2, %8
%9 = phi i32 [ %11, %8 ], [ 0, %2 ]
%10 = tail call i32 @strcat(i8* %6, i8* %1)
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i32 %11, %0
br i1 %12, label %13, label %8
13: ; preds = %8, %2
ret i8* %6
}