#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 */
double atof(char *);
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(void *);
void *malloc(size_t);
int /*<<< orphan*/ printf(char *, size_t, int, double);
int /*<<< orphan*/ sprintf(char *, char *, int, size_t, size_t, long, size_t);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usage(char *, char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc != 4) {
    usage(argv[0], "wrong number of arguments");
  }
  int cnt_i = atoi(argv[1]);
  if (cnt_i <= 0) {
    usage(argv[0], "number must be positive");
  }
  char buffer[1024];
  size_t cnt = (size_t)cnt_i;
  void *prev = NULL;
  void *pprev = NULL;
  size_t size = 1;
  int summand = atoi(argv[2]);
  void *base = malloc(1);
  void *pbase = base;
  double factor = atof(argv[3]);
  printf("cnt=%zd summand=%d factor=%f\n", cnt, summand, factor);
  for (int i = 0; i < cnt; i++) {
    void *ptr = malloc(size);
    free(pprev);
    pprev = prev;
    prev = ptr;
    size_t rel = (size_t)(ptr - base);
    long diff = (long)(ptr - pbase);
    pbase = ptr;
    size_t *isize = (size_t *)(ptr - 8);
    sprintf(buffer, "i=%d s=%zd rel=%zd diff=%ld isize=%zd\n", i, size, rel,
            diff, *isize);
    write(1, buffer, strlen(buffer));
    size = (size_t)(summand + factor * size);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11d6 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe57(%rip),%rsi
call   1090 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1203 <main+0x63>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe44(%rip),%rsi
call   1090 <usage@plt>
movslq -0x14(%rbp),%rax
mov    %rax,-0x428(%rbp)
movq   $0x0,-0x430(%rbp)
movq   $0x0,-0x438(%rbp)
movq   $0x1,-0x440(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x444(%rbp)
mov    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x450(%rbp)
mov    -0x450(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x460(%rbp)
ff
mov    -0x428(%rbp),%rsi
mov    -0x444(%rbp),%edx
movsd  -0x460(%rbp),%xmm0
ff
lea    0xdc8(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x464(%rbp)
movslq -0x464(%rbp),%rax
cmp    -0x428(%rbp),%rax
jae    1427 <main+0x287>
mov    -0x440(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x470(%rbp)
mov    -0x438(%rbp),%rdi
call   1030 <free@plt>
mov    -0x430(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x470(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x470(%rbp),%rax
mov    -0x450(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x478(%rbp)
mov    -0x470(%rbp),%rax
mov    -0x458(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x480(%rbp)
mov    -0x470(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x470(%rbp),%rax
add    $0xfffffffffffffff8,%rax
mov    %rax,-0x488(%rbp)
mov    -0x464(%rbp),%edx
mov    -0x440(%rbp),%rcx
mov    -0x478(%rbp),%r8
mov    -0x480(%rbp),%r9
mov    -0x488(%rbp),%rax
mov    (%rax),%rsi
mov    %rsp,%rax
mov    %rsi,(%rax)
lea    0xd06(%rip),%rsi
lea    -0x420(%rbp),%rdi
mov    %rdi,-0x490(%rbp)
call   10b0 <sprintf@plt>
mov    -0x490(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x490(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1050 <write@plt>
cvtsi2sdl -0x444(%rbp),%xmm1
ff
movsd  -0x460(%rbp),%xmm0
ff
movaps 0xc45(%rip),%xmm3
movq   -0x440(%rbp),%xmm2
ff
punpckldq %xmm3,%xmm2
movapd 0xc41(%rip),%xmm3
subpd  %xmm3,%xmm2
movaps %xmm2,%xmm3
unpckhpd %xmm2,%xmm2
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xc23(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x440(%rbp)
mov    -0x464(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x464(%rbp)
jmp    12a1 <main+0x101>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rsi,%rbp
cmp    $0x4,%edi
je     11c9 <main+0x29>
mov    0x0(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1090 <usage@plt>
mov    0x8(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r12d
test   %eax,%eax
jg     11e9 <main+0x49>
mov    0x0(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <usage@plt>
movslq %r12d,%r14
mov    0x10(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r13d
mov    $0x1,%ebx
mov    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    0x18(%rbp),%rdi
call   1040 <atof@plt>
lea    0xe3e(%rip),%rdi
mov    %r14,%rbp
mov    %r14,%rsi
mov    %r13d,%edx
movsd  %xmm0,0x20(%rsp)
call   1070 <printf@plt>
test   %r12d,%r12d
je     1332 <main+0x192>
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
movsd  %xmm0,0x10(%rsp)
cmp    $0x2,%rbp
cmovb  %rbx,%rbp
mov    %rbp,0x18(%rsp)
xor    %r12d,%r12d
xor    %r15d,%r15d
xor    %r14d,%r14d
mov    0x8(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,0x28(%rsp)
mov    %rbx,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%r8
sub    0x8(%rsp),%r8
mov    -0x8(%r15),%rax
mov    %r15,%r9
sub    %r13,%r9
mov    %rax,(%rsp)
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
lea    0xdcb(%rip),%rsi
mov    %r12d,%edx
mov    %rbx,%rcx
call   10b0 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <write@plt>
movq   %rbx,%xmm0
punpckldq 0xd24(%rip),%xmm0
subpd  0xd2c(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
mulsd  0x20(%rsp),%xmm1
addsd  0x10(%rsp),%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  0xd10(%rip),%xmm1
cvttsd2si %xmm1,%rbx
and    %rcx,%rbx
or     %rax,%rbx
add    $0x1,%r12
mov    0x28(%rsp),%r14
mov    %r15,%r13
cmp    %r12,0x18(%rsp)
jne    1270 <main+0xd0>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"wrong number of arguments\00"
@.str.1 = [24 x i8] c"number must be positive\00"
@.str.2 = [30 x i8] c"cnt=%zd summand=%d factor=%f\0A\00"
@.str.3 = [39 x i8] c"i=%d s=%zd rel=%zd diff=%ld isize=%zd\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca double
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 4
br i1 %22, label %23, label %28
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @usage(i8* %26, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %23, %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp sle i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %28
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = call i32 @usage(i8* %38, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %35, %28
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
store i64 %42, i64* %8
store i8* null, i8** %9
store i8* null, i8** %10
store i64 1, i64* %11
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @atoi(i8* %45)
store i32 %46, i32* %12
%47 = call i8* @malloc(i64 1)
store i8* %47, i8** %13
%48 = load i8*, i8** %13
store i8* %48, i8** %14
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
%52 = call double @atof(i8* %51)
store double %52, double* %15
%53 = load i64, i64* %8
%54 = load i32, i32* %12
%55 = load double, double* %15
%56 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %53, i32 %54, double %55)
store i32 0, i32* %16
br label %57
57: ; preds = %102, %40
%58 = load i32, i32* %16
%59 = sext i32 %58 to i64
%60 = load i64, i64* %8
%61 = icmp ult i64 %59, %60
br i1 %61, label %62, label %105
62: ; preds = %57
%63 = load i64, i64* %11
%64 = call i8* @malloc(i64 %63)
store i8* %64, i8** %17
%65 = load i8*, i8** %10
%66 = call i32 @free(i8* %65)
%67 = load i8*, i8** %9
store i8* %67, i8** %10
%68 = load i8*, i8** %17
store i8* %68, i8** %9
%69 = load i8*, i8** %17
%70 = load i8*, i8** %13
%71 = ptrtoint i8* %69 to i64
%72 = ptrtoint i8* %70 to i64
%73 = sub i64 %71, %72
store i64 %73, i64* %18
%74 = load i8*, i8** %17
%75 = load i8*, i8** %14
%76 = ptrtoint i8* %74 to i64
%77 = ptrtoint i8* %75 to i64
%78 = sub i64 %76, %77
store i64 %78, i64* %19
%79 = load i8*, i8** %17
store i8* %79, i8** %14
%80 = load i8*, i8** %17
%81 = getelementptr i8, i8* %80, i64 -8
%82 = bitcast i8* %81 to i64*
store i64* %82, i64** %20
%83 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%84 = load i32, i32* %16
%85 = load i64, i64* %11
%86 = load i64, i64* %18
%87 = load i64, i64* %19
%88 = load i64*, i64** %20
%89 = load i64, i64* %88
%90 = call i32 @sprintf(i8* %83, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %84, i64 %85, i64 %86, i64 %87, i64 %89)
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%92 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%93 = call i32 @strlen(i8* %92)
%94 = call i32 @write(i32 1, i8* %91, i32 %93)
%95 = load i32, i32* %12
%96 = sitofp i32 %95 to double
%97 = load double, double* %15
%98 = load i64, i64* %11
%99 = uitofp i64 %98 to double
%100 = call double @llvm.fmuladd.f64(double %97, double %99, double %96)
%101 = fptoui double %100 to i64
store i64 %101, i64* %11
br label %102
102: ; preds = %62
%103 = load i32, i32* %16
%104 = add nsw i32 %103, 1
store i32 %104, i32* %16
br label %57
105: ; preds = %57
%106 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [26 x i8] c"wrong number of arguments\00"
@.str.1 = [24 x i8] c"number must be positive\00"
@.str.2 = [30 x i8] c"cnt=%zd summand=%d factor=%f\0A\00"
@.str.3 = [39 x i8] c"i=%d s=%zd rel=%zd diff=%ld isize=%zd\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp eq i32 %0, 4
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @usage(i8* %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %5, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %1
%15 = tail call i32 @usage(i8* %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %13, %8
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = sext i32 %11 to i64
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = tail call dereferenceable_or_null(1) i8* @malloc(i64 1)
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call double @atof(i8* %24)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %18, i32 %21, double %25)
%27 = icmp eq i32 %11, 0
br i1 %27, label %32, label %28
28: ; preds = %16
%29 = ptrtoint i8* %22 to i64
%30 = sitofp i32 %21 to double
%31 = call i64 @llvm.umax.i64(i64 %18, i64 1)
br label %34
32: ; preds = %34, %16
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %28, %34
%35 = phi i64 [ 0, %28 ], [ %56, %34 ]
%36 = phi i8* [ null, %28 ], [ %40, %34 ]
%37 = phi i8* [ null, %28 ], [ %36, %34 ]
%38 = phi i64 [ 1, %28 ], [ %55, %34 ]
%39 = phi i8* [ %22, %28 ], [ %40, %34 ]
%40 = call i8* @malloc(i64 %38)
%41 = call i32 @free(i8* %37)
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %42, %29
%44 = ptrtoint i8* %39 to i64
%45 = sub i64 %42, %44
%46 = getelementptr i8, i8* %40, i64 -8
%47 = bitcast i8* %46 to i64*
%48 = load i64, i64* %47
%49 = trunc i64 %35 to i32
%50 = call i32 @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %49, i64 %38, i64 %43, i64 %45, i64 %48)
%51 = call i32 @strlen(i8* %17)
%52 = call i32 @write(i32 1, i8* %17, i32 %51)
%53 = uitofp i64 %38 to double
%54 = call double @llvm.fmuladd.f64(double %25, double %53, double %30)
%55 = fptoui double %54 to i64
%56 = add nuw i64 %35, 1
%57 = icmp eq i64 %56, %31
br i1 %57, label %32, label %34
}