#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 int /*<<< orphan*/ uint8_t;
typedef int uint16_t;
typedef int time_t;
struct ts_tdt {
  int dummy;
};
struct tm {
  int tm_year;
};

/* Variables and functions */
int euro_dst_end(int);
int euro_dst_start(int);
int /*<<< orphan*/ gmtime_r(int *, struct tm *);
int /*<<< orphan*/ ts_tot_set_localtime_offset(struct ts_tdt *, int, int,
                                               int /*<<< orphan*/, int, int);
void ts_tot_set_localtime_offset_sofia(struct ts_tdt *tdt, time_t now) {
  uint8_t polarity = 0;
  time_t change_time;
  uint16_t current_offset;
  uint16_t next_offset;
  struct tm tm;
  gmtime_r(&now, &tm);
  int curyear = tm.tm_year + 1900;
  int dst_start_date = euro_dst_start(curyear);
  int dst_end_date = euro_dst_end(curyear);
  if (now < dst_start_date) {
    current_offset = 0x0200;
    next_offset = 0x0300;
    change_time = dst_start_date;
  } else {
    if (now >= dst_start_date && now < dst_end_date) {
      current_offset = 0x0300;
      next_offset = 0x0200;
      change_time = dst_end_date;
    } else {
      current_offset = 0x0200;
      next_offset = 0x0300;
      change_time = euro_dst_start(curyear + 1);
    }
  }
  ts_tot_set_localtime_offset(tdt, now, change_time, polarity, current_offset,
                              next_offset);
}


x86 assembly (clang, -O0):
<ts_tot_set_localtime_offset_sofia>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0xc(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <gmtime_r@plt>
mov    -0x20(%rbp),%eax
add    $0x76c,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <euro_dst_start@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1040 <euro_dst_end@plt>
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11a9 <ts_tot_set_localtime_offset_sofia+0x69>
movl   $0x200,-0x18(%rbp)
movl   $0x300,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11fb <ts_tot_set_localtime_offset_sofia+0xbb>
mov    -0xc(%rbp),%eax
cmp    -0x28(%rbp),%eax
jl     11da <ts_tot_set_localtime_offset_sofia+0x9a>
mov    -0xc(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11da <ts_tot_set_localtime_offset_sofia+0x9a>
movl   $0x300,-0x18(%rbp)
movl   $0x200,-0x1c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11f6 <ts_tot_set_localtime_offset_sofia+0xb6>
movl   $0x200,-0x18(%rbp)
movl   $0x300,-0x1c(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1050 <euro_dst_start@plt>
mov    %eax,-0x14(%rbp)
jmp    11fb <ts_tot_set_localtime_offset_sofia+0xbb>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
call   1060 <ts_tot_set_localtime_offset@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_tot_set_localtime_offset_sofia>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
mov    %esi,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <gmtime_r@plt>
mov    0x10(%rsp),%ebx
lea    0x76c(%rbx),%ebp
mov    %ebp,%edi
call   1050 <euro_dst_start@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1040 <euro_dst_end@plt>
mov    0xc(%rsp),%esi
cmp    %r15d,%esi
jge    1192 <ts_tot_set_localtime_offset_sofia+0x52>
mov    $0x200,%r8d
mov    $0x300,%r9d
jmp    11c7 <ts_tot_set_localtime_offset_sofia+0x87>
cmp    %eax,%esi
jge    11a7 <ts_tot_set_localtime_offset_sofia+0x67>
mov    $0x300,%r8d
mov    $0x200,%r9d
mov    %eax,%r15d
jmp    11c7 <ts_tot_set_localtime_offset_sofia+0x87>
add    $0x76d,%ebx
mov    %ebx,%edi
call   1050 <euro_dst_start@plt>
mov    %eax,%r15d
mov    $0x200,%r8d
mov    $0x300,%r9d
mov    0xc(%rsp),%esi
mov    %r14,%rdi
mov    %r15d,%edx
xor    %ecx,%ecx
call   1060 <ts_tot_set_localtime_offset@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ts_tdt = type { i32 }
%struct.tm = type { i32 }
define void @ts_tot_set_localtime_offset_sofia(%struct.ts_tdt* %0, i32 %1) {
%3 = alloca %struct.ts_tdt*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.tm
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store %struct.ts_tdt* %0, %struct.ts_tdt** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%13 = call i32 @gmtime_r(i32* %4, %struct.tm* %9)
%14 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1900
store i32 %16, i32* %10
%17 = load i32, i32* %10
%18 = call i32 @euro_dst_start(i32 %17)
store i32 %18, i32* %11
%19 = load i32, i32* %10
%20 = call i32 @euro_dst_end(i32 %19)
store i32 %20, i32* %12
%21 = load i32, i32* %4
%22 = load i32, i32* %11
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %2
store i32 512, i32* %7
store i32 768, i32* %8
%25 = load i32, i32* %11
store i32 %25, i32* %6
br label %41
26: ; preds = %2
%27 = load i32, i32* %4
%28 = load i32, i32* %11
%29 = icmp sge i32 %27, %28
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i32, i32* %4
%32 = load i32, i32* %12
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30
store i32 768, i32* %7
store i32 512, i32* %8
%35 = load i32, i32* %12
store i32 %35, i32* %6
br label %40
36: ; preds = %30, %26
store i32 512, i32* %7
store i32 768, i32* %8
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
%39 = call i32 @euro_dst_start(i32 %38)
store i32 %39, i32* %6
br label %40
40: ; preds = %36, %34
br label %41
41: ; preds = %40, %24
%42 = load %struct.ts_tdt*, %struct.ts_tdt** %3
%43 = load i32, i32* %4
%44 = load i32, i32* %6
%45 = load i32, i32* %5
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = call i32 @ts_tot_set_localtime_offset(%struct.ts_tdt* %42, i32 %43, i32 %44, i32 %45, i32 %46, i32 %47)
ret void
}

LLVM IR (-O2):
%struct.ts_tdt = type { i32 }
%struct.tm = type { i32 }
define void @ts_tot_set_localtime_offset_sofia(%struct.ts_tdt* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.tm
store i32 %1, i32* %3
%5 = bitcast %struct.tm* %4 to i8*
%6 = call i32 @gmtime_r(i32* %3, %struct.tm* %4)
%7 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = add nsw i32 %8, 1900
%10 = call i32 @euro_dst_start(i32 %9)
%11 = call i32 @euro_dst_end(i32 %9)
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, %10
br i1 %13, label %20, label %14
14: ; preds = %2
%15 = icmp slt i32 %12, %11
br i1 %15, label %20, label %16
16: ; preds = %14
%17 = add nsw i32 %8, 1901
%18 = call i32 @euro_dst_start(i32 %17)
%19 = load i32, i32* %3
br label %20
20: ; preds = %14, %2, %16
%21 = phi i32 [ %19, %16 ], [ %12, %2 ], [ %12, %14 ]
%22 = phi i32 [ 768, %16 ], [ 768, %2 ], [ 512, %14 ]
%23 = phi i32 [ 512, %16 ], [ 512, %2 ], [ 768, %14 ]
%24 = phi i32 [ %18, %16 ], [ %10, %2 ], [ %11, %14 ]
%25 = call i32 @ts_tot_set_localtime_offset(%struct.ts_tdt* %0, i32 %21, i32 %24, i32 0, i32 %23, i32 %22)
ret void
}