#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*/ memcpy(char *, char *, size_t);
size_t strlen(char *);
void dostuff(int i) {
  if (i > 500)
    return;
  char *pass = "password=mypass";
  char *p;
  int j;
  for (j = 0; j < 40; j++) {
    p = malloc(strlen(pass) + 1);
    memcpy(p, pass, strlen(pass));
    p[strlen(pass)] = (char)((j + i) % 80) + 31;
  }
  dostuff(i + 1);
}


x86 assembly (clang, -O0):
<dostuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x1f4,-0x4(%rbp)
jle    115d <dostuff+0x1d>
jmp    120a <dostuff+0xca>
lea    0xe9c(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x28,-0x1c(%rbp)
jge    11ff <dostuff+0xbf>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    -0x4(%rbp),%eax
mov    $0x50,%ecx
cltd
idiv   %ecx
mov    %dl,%al
movsbl %al,%eax
add    $0x1f,%eax
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x29(%rbp),%dl
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116f <dostuff+0x2f>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
call   1050 <dostuff@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dostuff>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1f4,%edi
jg     11ab <dostuff+0x8b>
mov    %edi,%r15d
lea    0xec6(%rip),%r14
nopw   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    $0xf,%edx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <memcpy@plt>
lea    (%r15,%rbx,1),%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
shl    $0x4,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    $0x1f,%al
mov    %al,0xf(%r12)
add    $0x1,%ebx
cmp    $0x28,%ebx
jne    1150 <dostuff+0x30>
add    $0x1,%r15d
cmp    $0x1f5,%r15d
jne    1140 <dostuff+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"password=mypass\00"
define void @dostuff(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = icmp sgt i32 %6, 500
br i1 %7, label %8, label %9
8: ; preds = %1
br label %42
9: ; preds = %1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 0, i32* %5
br label %10
10: ; preds = %36, %9
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 40
br i1 %12, label %13, label %39
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = call i64 @strlen(i8* %14)
%16 = add i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = load i8*, i8** %3
%21 = load i8*, i8** %3
%22 = call i64 @strlen(i8* %21)
%23 = call i32 @memcpy(i8* %19, i8* %20, i64 %22)
%24 = load i32, i32* %5
%25 = load i32, i32* %2
%26 = add nsw i32 %24, %25
%27 = srem i32 %26, 80
%28 = trunc i32 %27 to i8
%29 = sext i8 %28 to i32
%30 = add nsw i32 %29, 31
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %4
%33 = load i8*, i8** %3
%34 = call i64 @strlen(i8* %33)
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
br label %36
36: ; preds = %13
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %10
39: ; preds = %10
%40 = load i32, i32* %2
%41 = add nsw i32 %40, 1
br label %42
42: ; preds = %39, %8
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"password=mypass\00"
define void @dostuff(i32 %0) {
%2 = icmp sgt i32 %0, 500
br i1 %2, label %19, label %3
3: ; preds = %1, %16
%4 = phi i32 [ %17, %16 ], [ %0, %1 ]
br label %5
5: ; preds = %3, %5
%6 = phi i32 [ 0, %3 ], [ %14, %5 ]
%7 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%8 = tail call i32 @memcpy(i8* %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 15)
%9 = add nsw i32 %6, %4
%10 = srem i32 %9, 80
%11 = trunc i32 %10 to i8
%12 = add nsw i8 %11, 31
%13 = getelementptr inbounds i8, i8* %7, i64 15
store i8 %12, i8* %13
%14 = add nuw nsw i32 %6, 1
%15 = icmp eq i32 %14, 40
br i1 %15, label %16, label %5
16: ; preds = %5
%17 = add i32 %4, 1
%18 = icmp eq i32 %17, 501
br i1 %18, label %19, label %3
19: ; preds = %16, %1
ret void
}