#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 */
typedef long time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ gmtime_r(long *, struct tm *);
scalar_t__ malloc(long);
int /*<<< orphan*/ stderr;
struct tm *makeit(long ndates) {
  struct tm *date_array = (struct tm *)malloc(ndates * sizeof(struct tm));
  if (!date_array) {
    fprintf(stderr, "Too much malloc\n");
    exit(1);
  }
  long s;
  for (s = 0; s < ndates; s++) {
    time_t t = s + 1;
    gmtime_r(&t, &date_array[s]);
  }
  return date_array;
}


x86 assembly (clang, -O0):
<makeit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1187 <makeit+0x47>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    11d2 <makeit+0x92>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    -0x20(%rbp),%rdi
call   1030 <gmtime_r@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    118f <makeit+0x4f>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makeit>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r12
lea    0x0(,%rdi,4),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b7 <makeit+0x77>
mov    %rax,%r14
test   %r12,%r12
jle    11a6 <makeit+0x66>
neg    %r12
mov    $0x1,%ebx
lea    0x8(%rsp),%r15
mov    %r14,%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,0x8(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <gmtime_r@plt>
add    $0x4,%r13
lea    (%r12,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
jne    1180 <makeit+0x40>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"Too much malloc\0A\00"
define %struct.tm* @makeit(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.tm*
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %2
%6 = load i64, i64* %2
%7 = mul i64 %6, 4
%8 = call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to %struct.tm*
store %struct.tm* %9, %struct.tm** %3
%10 = load %struct.tm*, %struct.tm** %3
%11 = icmp ne %struct.tm* %10, null
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
store i64 0, i64* %4
br label %17
17: ; preds = %28, %16
%18 = load i64, i64* %4
%19 = load i64, i64* %2
%20 = icmp slt i64 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i64, i64* %4
%23 = add nsw i64 %22, 1
store i64 %23, i64* %5
%24 = load %struct.tm*, %struct.tm** %3
%25 = load i64, i64* %4
%26 = getelementptr inbounds %struct.tm, %struct.tm* %24, i64 %25
%27 = call i32 @gmtime_r(i64* %5, %struct.tm* %26)
br label %28
28: ; preds = %21
%29 = load i64, i64* %4
%30 = add nsw i64 %29, 1
store i64 %30, i64* %4
br label %17
31: ; preds = %17
%32 = load %struct.tm*, %struct.tm** %3
ret %struct.tm* %32
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"Too much malloc\0A\00"
define %struct.tm* @makeit(i64 %0) {
%2 = alloca i64
%3 = shl i64 %0, 2
%4 = tail call i64 @malloc(i64 %3)
%5 = inttoptr i64 %4 to %struct.tm*
%6 = icmp eq i64 %4, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = icmp sgt i64 %0, 0
br i1 %8, label %9, label %21
9: ; preds = %7
%10 = bitcast i64* %2 to i8*
br label %15
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %15
%16 = phi i64 [ 0, %9 ], [ %17, %15 ]
%17 = add nuw nsw i64 %16, 1
store i64 %17, i64* %2
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 %16
%19 = call i32 @gmtime_r(i64* %2, %struct.tm* %18)
%20 = icmp eq i64 %17, %0
br i1 %20, label %21, label %15
21: ; preds = %15, %7
ret %struct.tm* %5
}