#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;
  int tm_mon;
  int tm_year;
};

/* Variables and functions */
struct tm *localtime(scalar_t__ *);
scalar_t__ mktime(struct tm *);
time_t addToDate(time_t ts, char unit, int num) {
  if (unit == 'h') {
    return ts + (3600 * num);
  } else {
    struct tm *t = localtime(&ts);
    switch (unit) {
    case 'd':
      t->tm_mday += num;
      break;
    case 'm':
      t->tm_mon += num;
      break;
    case 'y':
      t->tm_year += num;
      break;
    default:
      break;
    }
    return mktime(t);
  }
}


x86 assembly (clang, -O0):
<addToDate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x68,%eax
jne    115c <addToDate+0x3c>
mov    -0x10(%rbp),%rax
imul   $0xe10,-0x18(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11e6 <addToDate+0xc6>
lea    -0x10(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
movsbl -0x11(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x64,%eax
je     11a0 <addToDate+0x80>
jmp    117e <addToDate+0x5e>
mov    -0x24(%rbp),%eax
sub    $0x6d,%eax
je     11b0 <addToDate+0x90>
jmp    118f <addToDate+0x6f>
mov    -0x24(%rbp),%eax
sub    $0x79,%eax
je     11c2 <addToDate+0xa2>
jmp    11d4 <addToDate+0xb4>
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
jmp    11d9 <addToDate+0xb9>
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%rax
add    0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
jmp    11d9 <addToDate+0xb9>
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%rax
add    0x8(%rax),%ecx
mov    %ecx,0x8(%rax)
jmp    11d9 <addToDate+0xb9>
jmp    11d9 <addToDate+0xb9>
mov    -0x20(%rbp),%rdi
call   1040 <mktime@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addToDate>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rdi,(%rsp)
cmp    $0x68,%sil
jne    113c <addToDate+0x1c>
imul   $0xe10,%ebx,%eax
cltq
add    %rdi,%rax
jmp    1176 <addToDate+0x56>
movsbl %sil,%ebp
mov    %rsp,%rdi
call   1030 <localtime@plt>
cmp    $0x79,%ebp
je     115c <addToDate+0x3c>
cmp    $0x6d,%ebp
je     1165 <addToDate+0x45>
cmp    $0x64,%ebp
jne    116e <addToDate+0x4e>
mov    %rax,%rcx
jmp    116c <addToDate+0x4c>
mov    %rax,%rcx
add    $0x8,%rcx
jmp    116c <addToDate+0x4c>
mov    %rax,%rcx
add    $0x4,%rcx
add    %ebx,(%rcx)
mov    %rax,%rdi
call   1040 <mktime@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
define i64 @addToDate(i64 %0, i8 signext %1, i32 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8
%7 = alloca i32
%8 = alloca %struct.tm*
store i64 %0, i64* %5
store i8 %1, i8* %6
store i32 %2, i32* %7
%9 = load i8, i8* %6
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 104
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i64, i64* %5
%14 = load i32, i32* %7
%15 = mul nsw i32 3600, %14
%16 = sext i32 %15 to i64
%17 = add nsw i64 %13, %16
store i64 %17, i64* %4
br label %44
18: ; preds = %3
%19 = call %struct.tm* @localtime(i64* %5)
store %struct.tm* %19, %struct.tm** %8
%20 = load i8, i8* %6
%21 = sext i8 %20 to i32
switch i32 %21, label %40 [
i32 100, label %22
i32 109, label %28
i32 121, label %34
]
22: ; preds = %18
%23 = load i32, i32* %7
%24 = load %struct.tm*, %struct.tm** %8
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = add nsw i32 %26, %23
store i32 %27, i32* %25
br label %41
28: ; preds = %18
%29 = load i32, i32* %7
%30 = load %struct.tm*, %struct.tm** %8
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 1
%32 = load i32, i32* %31
%33 = add nsw i32 %32, %29
store i32 %33, i32* %31
br label %41
34: ; preds = %18
%35 = load i32, i32* %7
%36 = load %struct.tm*, %struct.tm** %8
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 2
%38 = load i32, i32* %37
%39 = add nsw i32 %38, %35
store i32 %39, i32* %37
br label %41
40: ; preds = %18
br label %41
41: ; preds = %40, %34, %28, %22
%42 = load %struct.tm*, %struct.tm** %8
%43 = call i64 @mktime(%struct.tm* %42)
store i64 %43, i64* %4
br label %44
44: ; preds = %41, %12
%45 = load i64, i64* %4
ret i64 %45
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
define i64 @addToDate(i64 %0, i8 signext %1, i32 %2) {
%4 = alloca i64
store i64 %0, i64* %4
%5 = icmp eq i8 %1, 104
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = mul nsw i32 %2, 3600
%8 = sext i32 %7 to i64
%9 = add nsw i64 %8, %0
br label %25
10: ; preds = %3
%11 = sext i8 %1 to i32
%12 = call %struct.tm* @localtime(i64* %4)
switch i32 %11, label %23 [
i32 100, label %13
i32 109, label %15
i32 121, label %17
]
13: ; preds = %10
%14 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 0
br label %19
15: ; preds = %10
%16 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 1
br label %19
17: ; preds = %10
%18 = getelementptr inbounds %struct.tm, %struct.tm* %12, i64 0, i32 2
br label %19
19: ; preds = %13, %15, %17
%20 = phi i32* [ %18, %17 ], [ %16, %15 ], [ %14, %13 ]
%21 = load i32, i32* %20
%22 = add nsw i32 %21, %2
store i32 %22, i32* %20
br label %23
23: ; preds = %19, %10
%24 = call i64 @mktime(%struct.tm* %12)
br label %25
25: ; preds = %23, %6
%26 = phi i64 [ %9, %6 ], [ %24, %23 ]
ret i64 %26
}