#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, int);
int /*<<< orphan*/ printf(char *, ...);
int foo() {
  static int recursive_times = 0;
  char data[1024];
  int i = 0;
  if (recursive_times++ > 1024) {
    recursive_times = 0;
    return 0;
  }
  printf("About to memset: recursive_times = %d\n", recursive_times);
  for (i = 0; i < 1024; i++) {
    memset(data, 0, 1024);
    memset(data, 0xFF, 1024);
  }
  printf("About to call foo...\n");
  return foo();
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x414(%rbp)
mov    0x2ef1(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2ee6(%rip)
cmp    $0x400,%eax
jle    1177 <foo+0x47>
movl   $0x0,0x2ed1(%rip)
movl   $0x0,-0x4(%rbp)
jmp    11f8 <foo+0xc8>
mov    0x2ebf(%rip),%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x414(%rbp)
cmpl   $0x400,-0x414(%rbp)
jge    11e2 <foo+0xb2>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    $0xff,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    1195 <foo+0x65>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
call   1050 <foo@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    0x2ef5(%rip),%eax
lea    0x1(%rax),%esi
mov    %esi,0x2eec(%rip)
cmp    $0x401,%eax
jl     116b <foo+0x2b>
movl   $0x0,0x2edb(%rip)
jmp    11c7 <foo+0x87>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x400,%ebp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
add    $0xffffffff,%ebp
jne    1190 <foo+0x50>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
call   1060 <foo@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@foo.recursive_times = internal global i32 0
@.str = [39 x i8] c"About to memset: recursive_times = %d\0A\00"
@.str.1 = [22 x i8] c"About to call foo...\0A\00"
define i32 @foo() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32
store i32 0, i32* %3
%4 = load i32, i32* @foo.recursive_times
%5 = add nsw i32 %4, 1
store i32 %5, i32* @foo.recursive_times
%6 = icmp sgt i32 %4, 1024
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 0, i32* @foo.recursive_times
store i32 0, i32* %1
br label %25
8: ; preds = %0
%9 = load i32, i32* @foo.recursive_times
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 0, i32* %3
br label %11
11: ; preds = %19, %8
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 1024
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 1024)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 255, i32 1024)
br label %19
19: ; preds = %14
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %11
22: ; preds = %11
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @foo()
store i32 %24, i32* %1
br label %25
25: ; preds = %22, %7
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@foo.recursive_times = internal unnamed_addr global i32 0
@.str = [39 x i8] c"About to memset: recursive_times = %d\0A\00"
@str = [21 x i8] c"About to call foo...\00"
define i32 @foo() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @foo.recursive_times
%4 = add nsw i32 %3, 1
store i32 %4, i32* @foo.recursive_times
%5 = icmp sgt i32 %3, 1024
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 0, i32* @foo.recursive_times
br label %18
7: ; preds = %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %9
9: ; preds = %7, %9
%10 = phi i32 [ 0, %7 ], [ %13, %9 ]
%11 = call i32 @memset(i8* %2, i32 0, i32 1024)
%12 = call i32 @memset(i8* %2, i32 255, i32 1024)
%13 = add nuw nsw i32 %10, 1
%14 = icmp eq i32 %13, 1024
br i1 %14, label %15, label %9
15: ; preds = %9
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%17 = call i32 @foo()
br label %18
18: ; preds = %15, %6
ret i32 0
}