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

/* Variables and functions */
int /*<<< orphan*/ column(char *, int, char *);
int date_days_between(char *, char *);
int /*<<< orphan*/ get_line(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, int, int, char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, int, int);
void test_payroll_period(void) {
  FILE *input_pipe;
  char input_buffer[128];
  int begin_year;
  int end_year;
  int year;
  int period_number;
  char *beginday;
  char *period;
  char sys_string[1024];
  char begin_date_string[16];
  char end_date_string[16];
  period = "biweekly";
  begin_year = 1970;
  end_year = 2030;
  beginday = "friday";
  for (year = begin_year; year <= end_year; year++) {
    for (period_number = 1;; period_number++) {
      sprintf(sys_string,
              "payroll_period.e	"
              "period=%s		"
              "beginday=%s		"
              "year=%d		"
              "number=%d		",
              period, beginday, year, period_number);
      input_pipe = popen(sys_string, "r");
      if (!get_line(input_buffer, input_pipe)) {
        pclose(input_pipe);
        break;
      }
      column(begin_date_string, 1, input_buffer);
      get_line(input_buffer, input_pipe);
      column(end_date_string, 1, input_buffer);
      pclose(input_pipe);
      printf("for year=%d/period=%d: days_between (%s and %s) = %d\n", year,
             period_number, begin_date_string, end_date_string,
             date_days_between(begin_date_string, end_date_string));
    }
  }
}


x86 assembly (clang, -O0):
<test_payroll_period>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4f0,%rsp
lea    0xe7e(%rip),%rax
mov    %rax,-0xb0(%rbp)
movl   $0x7b2,-0x94(%rbp)
movl   $0x7ee,-0x98(%rbp)
lea    0xe65(%rip),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x94(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
cmp    -0x98(%rbp),%eax
jg     1326 <test_payroll_period+0x1b6>
movl   $0x1,-0xa0(%rbp)
lea    -0x4b0(%rbp),%rdi
mov    -0xb0(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
mov    -0x9c(%rbp),%r8d
mov    -0xa0(%rbp),%r9d
lea    0xe13(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x4b0(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <get_line@plt>
cmp    $0x0,%eax
jne    1240 <test_payroll_period+0xd0>
mov    -0x8(%rbp),%rdi
call   1050 <pclose@plt>
jmp    130d <test_payroll_period+0x19d>
lea    -0x4c0(%rbp),%rdi
lea    -0x90(%rbp),%rdx
mov    $0x1,%esi
call   1070 <column@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <get_line@plt>
lea    -0x4d0(%rbp),%rdi
lea    -0x90(%rbp),%rdx
mov    $0x1,%esi
call   1070 <column@plt>
mov    -0x8(%rbp),%rdi
call   1050 <pclose@plt>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x4e8(%rbp)
mov    -0xa0(%rbp),%eax
mov    %eax,-0x4e4(%rbp)
lea    -0x4c0(%rbp),%rax
mov    %rax,-0x4e0(%rbp)
lea    -0x4d0(%rbp),%rax
mov    %rax,-0x4d8(%rbp)
lea    -0x4c0(%rbp),%rdi
lea    -0x4d0(%rbp),%rsi
call   1060 <date_days_between@plt>
mov    -0x4e8(%rbp),%esi
mov    -0x4e4(%rbp),%edx
mov    -0x4e0(%rbp),%rcx
mov    -0x4d8(%rbp),%r8
mov    %eax,%r9d
lea    0xd5c(%rip),%rdi
call   1040 <printf@plt>
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    11d3 <test_payroll_period+0x63>
jmp    1312 <test_payroll_period+0x1a2>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    11b7 <test_payroll_period+0x47>
add    $0x4f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_payroll_period>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4b8,%rsp
mov    $0x7b2,%r14d
lea    0xe82(%rip),%rsi
lea    0xe6b(%rip),%rdx
lea    0xe6d(%rip),%rcx
lea    0xb0(%rsp),%r15
lea    0xea3(%rip),%rbp
lea    0x30(%rsp),%r12
jmp    1202 <test_payroll_period+0x92>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
call   1050 <pclose@plt>
mov    0xc(%rsp),%r14d
add    $0x1,%r14d
cmp    $0x7ef,%r14d
lea    0xe31(%rip),%rsi
lea    0xe1a(%rip),%rdx
lea    0xe1c(%rip),%rcx
lea    0xb0(%rsp),%r15
lea    0xe52(%rip),%rbp
je     12ff <test_payroll_period+0x18f>
mov    %r15,%rdi
mov    %r14d,%r8d
mov    $0x1,%r9d
call   1090 <sprintf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1080 <popen@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    %rax,%rsi
call   1030 <get_line@plt>
test   %eax,%eax
mov    %r14d,0xc(%rsp)
je     11c0 <test_payroll_period+0x50>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
call   1070 <column@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <get_line@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
call   1070 <column@plt>
mov    %r13,%rdi
call   1050 <pclose@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <date_days_between@plt>
lea    0xdc1(%rip),%rdi
mov    0xc(%rsp),%r13d
mov    %r13d,%esi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %r15,%r8
mov    %eax,%r9d
call   1040 <printf@plt>
add    $0x1,%ebp
lea    0xb0(%rsp),%rbx
mov    %rbx,%rdi
lea    0xd54(%rip),%rsi
lea    0xd3d(%rip),%rdx
lea    0xd3f(%rip),%rcx
mov    %r13d,%r8d
mov    %ebp,%r9d
call   1090 <sprintf@plt>
mov    %rbx,%rdi
lea    0xd6f(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    %rax,%rsi
call   1030 <get_line@plt>
test   %eax,%eax
jne    1240 <test_payroll_period+0xd0>
jmp    11c0 <test_payroll_period+0x50>
add    $0x4b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"biweekly\00"
@.str.1 = [7 x i8] c"friday\00"
@.str.2 = [62 x i8] c"payroll_period.e\09period=%s\09\09beginday=%s\09\09year=%d\09\09number=%d\09\09\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [54 x i8] c"for year=%d/period=%d: days_between (%s and %s) = %d\0A\00"
define void @test_payroll_period() {
%1 = alloca i32*
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [1024 x i8]
%10 = alloca [16 x i8]
%11 = alloca [16 x i8]
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %8
store i32 1970, i32* %3
store i32 2030, i32* %4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %7
%12 = load i32, i32* %3
store i32 %12, i32* %5
br label %13
13: ; preds = %58, %0
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %61
17: ; preds = %13
store i32 1, i32* %6
br label %18
18: ; preds = %54, %17
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%20 = load i8*, i8** %8
%21 = load i8*, i8** %7
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i8* %20, i8* %21, i32 %22, i32 %23)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%26 = call i32* @popen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %26, i32** %1
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%28 = load i32*, i32** %1
%29 = call i32 @get_line(i8* %27, i32* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %18
%32 = load i32*, i32** %1
%33 = call i32 @pclose(i32* %32)
br label %57
34: ; preds = %18
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%37 = call i32 @column(i8* %35, i32 1, i8* %36)
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%39 = load i32*, i32** %1
%40 = call i32 @get_line(i8* %38, i32* %39)
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%43 = call i32 @column(i8* %41, i32 1, i8* %42)
%44 = load i32*, i32** %1
%45 = call i32 @pclose(i32* %44)
%46 = load i32, i32* %5
%47 = load i32, i32* %6
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%49 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%51 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%52 = call i32 @date_days_between(i8* %50, i8* %51)
%53 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i32 %46, i32 %47, i8* %48, i8* %49, i32 %52)
br label %54
54: ; preds = %34
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %18
57: ; preds = %31
br label %58
58: ; preds = %57
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
br label %13
61: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"biweekly\00"
@.str.1 = [7 x i8] c"friday\00"
@.str.2 = [62 x i8] c"payroll_period.e\09period=%s\09\09beginday=%s\09\09year=%d\09\09number=%d\09\09\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [54 x i8] c"for year=%d/period=%d: days_between (%s and %s) = %d\0A\00"
define void @test_payroll_period() {
%1 = alloca [128 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [16 x i8]
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
br label %9
9: ; preds = %0, %15
%10 = phi i32 [ 1970, %0 ], [ %18, %15 ]
%11 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 1)
%12 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @get_line(i8* %5, i32* %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %20, %9
%16 = phi i32* [ %12, %9 ], [ %31, %20 ]
%17 = call i32 @pclose(i32* %16)
%18 = add nuw nsw i32 %10, 1
%19 = icmp eq i32 %18, 2031
br i1 %19, label %34, label %9
20: ; preds = %9, %20
%21 = phi i32* [ %31, %20 ], [ %12, %9 ]
%22 = phi i32 [ %29, %20 ], [ 1, %9 ]
%23 = call i32 @column(i8* %7, i32 1, i8* %5)
%24 = call i32 @get_line(i8* %5, i32* %21)
%25 = call i32 @column(i8* %8, i32 1, i8* %5)
%26 = call i32 @pclose(i32* %21)
%27 = call i32 @date_days_between(i8* %7, i8* %8)
%28 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i32 %10, i32 %22, i8* %7, i8* %8, i32 %27)
%29 = add nuw nsw i32 %22, 1
%30 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %29)
%31 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @get_line(i8* %5, i32* %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %15, label %20
34: ; preds = %15
ret void
}