#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 unsigned long time_t;
struct tm {
  scalar_t__ tm_mday;
  scalar_t__ tm_mon;
  scalar_t__ tm_year;
};

/* Variables and functions */
int /*<<< orphan*/ localtime_r(unsigned long *, struct tm *);
unsigned long mktime(struct tm *);
unsigned long update_tm(struct tm *tm, struct tm *now, unsigned long sec) {
  time_t n;
  if (tm->tm_mday < 0)
    tm->tm_mday = now->tm_mday;
  if (tm->tm_mon < 0)
    tm->tm_mon = now->tm_mon;
  if (tm->tm_year < 0) {
    tm->tm_year = now->tm_year;
    if (tm->tm_mon > now->tm_mon)
      tm->tm_year--;
  }
  n = mktime(tm) - sec;
  localtime_r(&n, tm);
  return n;
}


x86 assembly (clang, -O0):
<update_tm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jge    1150 <update_tm+0x30>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jge    116f <update_tm+0x4f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,0x10(%rax)
jge    11b9 <update_tm+0x99>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%rax
jle    11b4 <update_tm+0x94>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x10(%rax)
jmp    11b9 <update_tm+0x99>
mov    -0x8(%rbp),%rdi
call   1040 <mktime@plt>
sub    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    -0x20(%rbp),%rdi
call   1030 <localtime_r@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_tm>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
cmpq   $0x0,(%rdi)
jns    1136 <update_tm+0x16>
mov    (%rsi),%rax
mov    %rax,(%rbx)
mov    0x8(%rbx),%rax
test   %rax,%rax
js     1148 <update_tm+0x28>
cmpq   $0x0,0x10(%rbx)
jns    116d <update_tm+0x4d>
jmp    1157 <update_tm+0x37>
mov    0x8(%rsi),%rax
mov    %rax,0x8(%rbx)
cmpq   $0x0,0x10(%rbx)
jns    116d <update_tm+0x4d>
mov    0x10(%rsi),%rcx
mov    %rcx,0x10(%rbx)
cmp    0x8(%rsi),%rax
jle    116d <update_tm+0x4d>
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x10(%rbx)
mov    %rbx,%rdi
call   1040 <mktime@plt>
sub    %r14,%rax
mov    %rax,(%rsp)
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <localtime_r@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i64, i64, i64 }
define i64 @update_tm(%struct.tm* %0, %struct.tm* %1, i64 %2) {
%4 = alloca %struct.tm*
%5 = alloca %struct.tm*
%6 = alloca i64
%7 = alloca i64
store %struct.tm* %0, %struct.tm** %4
store %struct.tm* %1, %struct.tm** %5
store i64 %2, i64* %6
%8 = load %struct.tm*, %struct.tm** %4
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load %struct.tm*, %struct.tm** %5
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 0
%15 = load i64, i64* %14
%16 = load %struct.tm*, %struct.tm** %4
%17 = getelementptr inbounds %struct.tm, %struct.tm* %16, i32 0, i32 0
store i64 %15, i64* %17
br label %18
18: ; preds = %12, %3
%19 = load %struct.tm*, %struct.tm** %4
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 1
%21 = load i64, i64* %20
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load %struct.tm*, %struct.tm** %5
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 1
%26 = load i64, i64* %25
%27 = load %struct.tm*, %struct.tm** %4
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 1
store i64 %26, i64* %28
br label %29
29: ; preds = %23, %18
%30 = load %struct.tm*, %struct.tm** %4
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 2
%32 = load i64, i64* %31
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %53
34: ; preds = %29
%35 = load %struct.tm*, %struct.tm** %5
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 2
%37 = load i64, i64* %36
%38 = load %struct.tm*, %struct.tm** %4
%39 = getelementptr inbounds %struct.tm, %struct.tm* %38, i32 0, i32 2
store i64 %37, i64* %39
%40 = load %struct.tm*, %struct.tm** %4
%41 = getelementptr inbounds %struct.tm, %struct.tm* %40, i32 0, i32 1
%42 = load i64, i64* %41
%43 = load %struct.tm*, %struct.tm** %5
%44 = getelementptr inbounds %struct.tm, %struct.tm* %43, i32 0, i32 1
%45 = load i64, i64* %44
%46 = icmp sgt i64 %42, %45
br i1 %46, label %47, label %52
47: ; preds = %34
%48 = load %struct.tm*, %struct.tm** %4
%49 = getelementptr inbounds %struct.tm, %struct.tm* %48, i32 0, i32 2
%50 = load i64, i64* %49
%51 = add nsw i64 %50, -1
store i64 %51, i64* %49
br label %52
52: ; preds = %47, %34
br label %53
53: ; preds = %52, %29
%54 = load %struct.tm*, %struct.tm** %4
%55 = call i64 @mktime(%struct.tm* %54)
%56 = load i64, i64* %6
%57 = sub i64 %55, %56
store i64 %57, i64* %7
%58 = load %struct.tm*, %struct.tm** %4
%59 = call i32 @localtime_r(i64* %7, %struct.tm* %58)
%60 = load i64, i64* %7
ret i64 %60
}

LLVM IR (-O2):
%struct.tm = type { i64, i64, i64 }
define i64 @update_tm(%struct.tm* %0, %struct.tm* nocapture %1, i64 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%7 = load i64, i64* %6
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
%11 = load i64, i64* %10
store i64 %11, i64* %6
br label %12
12: ; preds = %9, %3
%13 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%14 = load i64, i64* %13
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 1
%18 = load i64, i64* %17
store i64 %18, i64* %13
br label %19
19: ; preds = %16, %12
%20 = phi i64 [ %18, %16 ], [ %14, %12 ]
%21 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%22 = load i64, i64* %21
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 2
%26 = load i64, i64* %25
store i64 %26, i64* %21
%27 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 1
%28 = load i64, i64* %27
%29 = icmp sgt i64 %20, %28
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = add nsw i64 %26, -1
store i64 %31, i64* %21
br label %32
32: ; preds = %24, %30, %19
%33 = tail call i64 @mktime(%struct.tm* %0)
%34 = sub i64 %33, %2
store i64 %34, i64* %4
%35 = call i32 @localtime_r(i64* %4, %struct.tm* %0)
%36 = load i64, i64* %4
ret i64 %36
}