#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 *calloc(int, int);
scalar_t__ count_processes();
int /*<<< orphan*/ free(char *);
int list_processes(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int i = (int)count_processes();
  char *buffer = calloc((i * 43 + 1), 1);
  int retval = 0;
  if ((retval = list_processes(buffer, (i * 43 + 1))) > 0) {
    printf("%s\n", buffer);
    printf("Return value=%d\n", retval);
  }
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <count_processes@plt>
mov    %eax,-0x8(%rbp)
imul   $0x2b,-0x8(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
imul   $0x2b,-0x8(%rbp),%esi
add    $0x1,%esi
call   1070 <list_processes@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    11c4 <main+0x74>
mov    -0x10(%rbp),%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <count_processes@plt>
imul   $0x2b,%eax,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1080 <list_processes@plt>
test   %eax,%eax
jle    11a7 <main+0x47>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe62(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [17 x i8] c"Return value=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i64 (...) @count_processes()
%6 = trunc i64 %5 to i32
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = mul nsw i32 %7, 43
%9 = add nsw i32 %8, 1
%10 = call i8* @calloc(i32 %9, i32 1)
store i8* %10, i8** %3
store i32 0, i32* %4
%11 = load i8*, i8** %3
%12 = load i32, i32* %2
%13 = mul nsw i32 %12, 43
%14 = add nsw i32 %13, 1
%15 = call i32 @list_processes(i8* %11, i32 %14)
store i32 %15, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %0
%18 = load i8*, i8** %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %17, %0
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"Return value=%d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @count_processes()
%2 = trunc i64 %1 to i32
%3 = mul nsw i32 %2, 43
%4 = add nsw i32 %3, 1
%5 = tail call i8* @calloc(i32 %4, i32 1)
%6 = tail call i32 @list_processes(i8* %5, i32 %4)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) %5)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %11
11: ; preds = %8, %0
%12 = tail call i32 @free(i8* %5)
ret i32 0
}