#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 scalar_t__ time_t;
struct tm {
  int tm_mday;
  scalar_t__ tm_hour;
  scalar_t__ tm_min;
  scalar_t__ tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ localtime_r(scalar_t__ *, struct tm *);
scalar_t__ mktime(struct tm *);
scalar_t__ time(int /*<<< orphan*/ *);
time_t midnight(time_t now) {
  struct tm tm_now;
  if (now == (time_t)0)
    now = time(NULL);
  localtime_r(&now, &tm_now);
  tm_now.tm_sec = 0;
  tm_now.tm_min = 0;
  tm_now.tm_hour = 0;
  tm_now.tm_mday += 1;
  return (mktime(&tm_now));
}


x86 assembly (clang, -O0):
<midnight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1154 <midnight+0x24>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <localtime_r@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
call   1050 <mktime@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<midnight>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,0x8(%rsp)
test   %rdi,%rdi
jne    114b <midnight+0x1b>
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1030 <localtime_r@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
movq   $0x0,0x28(%rsp)
addl   $0x1,0x10(%rsp)
mov    %rbx,%rdi
call   1050 <mktime@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i64, i64, i64 }
define i64 @midnight(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.tm
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i64 @time(i32* null)
store i64 %7, i64* %2
br label %8
8: ; preds = %6, %1
%9 = call i32 @localtime_r(i64* %2, %struct.tm* %3)
%10 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 3
store i64 0, i64* %10
%11 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 2
store i64 0, i64* %11
%12 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 1
store i64 0, i64* %12
%13 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 0
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
store i32 %15, i32* %13
%16 = call i64 @mktime(%struct.tm* %3)
ret i64 %16
}

LLVM IR (-O2):
%struct.tm = type { i32, i64, i64, i64 }
define i64 @midnight(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.tm
store i64 %0, i64* %2
%4 = bitcast %struct.tm* %3 to i8*
%5 = icmp eq i64 %0, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i64 @time(i32* null)
store i64 %7, i64* %2
br label %8
8: ; preds = %6, %1
%9 = call i32 @localtime_r(i64* %2, %struct.tm* %3)
%10 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%11 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%12 = bitcast i64* %10 to i8*
%13 = load i32, i32* %11
%14 = add nsw i32 %13, 1
store i32 %14, i32* %11
%15 = call i64 @mktime(%struct.tm* %3)
ret i64 %15
}