#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 */

/* Variables and functions */
int get_current_century(int);
int get_next_century(int);
int get_previous_century(int);
int get_right_two_digits_of_current_year(int);
int calculate_full_year(int *difference, int year_entered,
                        int years_future_event, int optional_current_year) {
  int current_century;
  int previous_century;
  int next_century;
  int right_two_digits;
  int full_year;
  if (year_entered >= 1900)
    return year_entered;
  current_century = get_current_century(optional_current_year);
  previous_century = get_previous_century(optional_current_year);
  next_century = get_next_century(optional_current_year);
  right_two_digits =
      get_right_two_digits_of_current_year(optional_current_year);
  *difference = year_entered - right_two_digits;
  if (right_two_digits > years_future_event) {
    if (year_entered > years_future_event || *difference >= 0)
      full_year = current_century + year_entered;
    else
      full_year = next_century + year_entered;
  } else {
    if (year_entered <= years_future_event || *difference < 0)
      full_year = current_century + year_entered;
    else
      full_year = previous_century + year_entered;
  }
  return full_year;
}


x86 assembly (clang, -O0):
<calculate_full_year>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x76c,-0x14(%rbp)
jl     116d <calculate_full_year+0x2d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1221 <calculate_full_year+0xe1>
mov    -0x1c(%rbp),%edi
call   1050 <get_current_century@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <get_previous_century@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <get_next_century@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <get_right_two_digits_of_current_year@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%ecx
sub    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11e6 <calculate_full_year+0xa6>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11ca <calculate_full_year+0x8a>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jl     11d8 <calculate_full_year+0x98>
mov    -0x20(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    11e1 <calculate_full_year+0xa1>
mov    -0x28(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    121b <calculate_full_year+0xdb>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    11ff <calculate_full_year+0xbf>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jge    120d <calculate_full_year+0xcd>
mov    -0x20(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1216 <calculate_full_year+0xd6>
mov    -0x24(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    121b <calculate_full_year+0xdb>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_full_year>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
cmp    $0x76b,%esi
jg     11b9 <calculate_full_year+0x79>
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %rdi,%r15
mov    %ecx,%edi
call   1050 <get_current_century@plt>
mov    %eax,0x4(%rsp)
mov    %r14d,%edi
call   1060 <get_previous_century@plt>
mov    %eax,%r13d
mov    %r14d,%edi
call   1030 <get_next_century@plt>
mov    %eax,%ebp
mov    %r14d,%edi
call   1040 <get_right_two_digits_of_current_year@plt>
mov    %ebx,%ecx
sub    %eax,%ecx
mov    %ecx,(%r15)
cmp    %r12d,%eax
jle    11a3 <calculate_full_year+0x63>
test   %ecx,%ecx
mov    0x4(%rsp),%eax
cmovns %eax,%ebp
cmp    %r12d,%ebx
cmovg  %eax,%ebp
jmp    11b7 <calculate_full_year+0x77>
test   %ecx,%ecx
mov    0x4(%rsp),%eax
cmovs  %eax,%r13d
cmp    %r12d,%ebx
cmovle %eax,%r13d
mov    %r13d,%ebp
add    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calculate_full_year(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%15 = load i32, i32* %7
%16 = icmp sge i32 %15, 1900
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32, i32* %7
store i32 %18, i32* %5
br label %71
19: ; preds = %4
%20 = load i32, i32* %9
%21 = call i32 @get_current_century(i32 %20)
store i32 %21, i32* %10
%22 = load i32, i32* %9
%23 = call i32 @get_previous_century(i32 %22)
store i32 %23, i32* %11
%24 = load i32, i32* %9
%25 = call i32 @get_next_century(i32 %24)
store i32 %25, i32* %12
%26 = load i32, i32* %9
%27 = call i32 @get_right_two_digits_of_current_year(i32 %26)
store i32 %27, i32* %13
%28 = load i32, i32* %7
%29 = load i32, i32* %13
%30 = sub nsw i32 %28, %29
%31 = load i32*, i32** %6
store i32 %30, i32* %31
%32 = load i32, i32* %13
%33 = load i32, i32* %8
%34 = icmp sgt i32 %32, %33
br i1 %34, label %35, label %52
35: ; preds = %19
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = icmp sgt i32 %36, %37
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = load i32*, i32** %6
%41 = load i32, i32* %40
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39, %35
%44 = load i32, i32* %10
%45 = load i32, i32* %7
%46 = add nsw i32 %44, %45
store i32 %46, i32* %14
br label %51
47: ; preds = %39
%48 = load i32, i32* %12
%49 = load i32, i32* %7
%50 = add nsw i32 %48, %49
store i32 %50, i32* %14
br label %51
51: ; preds = %47, %43
br label %69
52: ; preds = %19
%53 = load i32, i32* %7
%54 = load i32, i32* %8
%55 = icmp sle i32 %53, %54
br i1 %55, label %60, label %56
56: ; preds = %52
%57 = load i32*, i32** %6
%58 = load i32, i32* %57
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %56, %52
%61 = load i32, i32* %10
%62 = load i32, i32* %7
%63 = add nsw i32 %61, %62
store i32 %63, i32* %14
br label %68
64: ; preds = %56
%65 = load i32, i32* %11
%66 = load i32, i32* %7
%67 = add nsw i32 %65, %66
store i32 %67, i32* %14
br label %68
68: ; preds = %64, %60
br label %69
69: ; preds = %68, %51
%70 = load i32, i32* %14
store i32 %70, i32* %5
br label %71
71: ; preds = %69, %17
%72 = load i32, i32* %5
ret i32 %72
}

LLVM IR (-O2):
define i32 @calculate_full_year(i32* nocapture writeonly %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %1, 1899
br i1 %5, label %26, label %6
6: ; preds = %4
%7 = tail call i32 @get_current_century(i32 %3)
%8 = tail call i32 @get_previous_century(i32 %3)
%9 = tail call i32 @get_next_century(i32 %3)
%10 = tail call i32 @get_right_two_digits_of_current_year(i32 %3)
%11 = sub nsw i32 %1, %10
store i32 %11, i32* %0
%12 = icmp sgt i32 %10, %2
br i1 %12, label %13, label %18
13: ; preds = %6
%14 = icmp sgt i32 %1, %2
%15 = icmp sgt i32 %11, -1
%16 = select i1 %14, i1 true, i1 %15
%17 = select i1 %16, i32 %7, i32 %9
br label %23
18: ; preds = %6
%19 = icmp sle i32 %1, %2
%20 = icmp slt i32 %11, 0
%21 = select i1 %19, i1 true, i1 %20
%22 = select i1 %21, i32 %7, i32 %8
br label %23
23: ; preds = %18, %13
%24 = phi i32 [ %17, %13 ], [ %22, %18 ]
%25 = add nsw i32 %24, %1
br label %26
26: ; preds = %4, %23
%27 = phi i32 [ %25, %23 ], [ %1, %4 ]
ret i32 %27
}