#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 */
struct tm {
  int tm_mon;
  int tm_mday;
  scalar_t__ tm_year;
};

/* Variables and functions */
int sprintf(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int convert_date(struct tm *date_p) {
  int buffer_i = 0;
  int date_return = 0;
  char buffer_c[2] = "";
  char year_tmp[5], month_tmp[3], day_tmp[3];
  buffer_i = sprintf(year_tmp, "%d", buffer_i);
  buffer_i = date_p->tm_mon + 1;
  if (buffer_i < 10) {
    sprintf(buffer_c, "%d", buffer_i);
    month_tmp[0] = '0';
    month_tmp[1] = buffer_c[0];
    month_tmp[2] = '\0';
  } else
    sprintf(month_tmp, "%d", buffer_i);
  strncpy(buffer_c, "", 3);
  buffer_i = date_p->tm_mday;
  if (buffer_i < 10) {
    sprintf(buffer_c, "%d", buffer_i);
    day_tmp[0] = '0';
    day_tmp[1] = buffer_c[0];
    day_tmp[2] = '\0';
  } else
    sprintf(day_tmp, "%d", buffer_i);
  date_return = ((((int)date_p->tm_year) + 1900) * 10000) +
                (((int)date_p->tm_mon) + 1) * 100 + ((int)date_p->tm_mday);
  return date_return;
}


x86 assembly (clang, -O0):
<convert_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x12(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <memset@plt>
lea    -0x17(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe98(%rip),%rsi
call   1050 <sprintf@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11ac <convert_date+0x7c>
lea    -0x12(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe6c(%rip),%rsi
call   1050 <sprintf@plt>
movb   $0x30,-0x1a(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x19(%rbp)
movb   $0x0,-0x18(%rbp)
jmp    11bf <convert_date+0x8f>
lea    -0x1a(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe46(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x12(%rbp),%rdi
lea    0xe38(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    120e <convert_date+0xde>
lea    -0x12(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe0a(%rip),%rsi
call   1050 <sprintf@plt>
movb   $0x30,-0x1d(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x1c(%rbp)
movb   $0x0,-0x1b(%rbp)
jmp    1221 <convert_date+0xf1>
lea    -0x1d(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xde4(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
add    $0x76c,%eax
imul   $0x2710,%eax,%eax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
imul   $0x64,%ecx,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%rcx
add    0x4(%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_date>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movw   $0x0,0x2(%rsp)
lea    0xec6(%rip),%r14
lea    0xb(%rsp),%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <sprintf@plt>
mov    (%rbx),%eax
lea    0x1(%rax),%edx
cmp    $0x9,%eax
lea    0x2(%rsp),%r15
lea    0x8(%rsp),%rdi
cmovl  %r15,%rdi
mov    %r14,%rsi
call   1040 <sprintf@plt>
lea    0xe94(%rip),%rsi
mov    %r15,%rdi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    0x4(%rbx),%edx
lea    0xe7b(%rip),%rsi
cmp    $0x9,%edx
jg     119b <convert_date+0x7b>
lea    0x2(%rsp),%rdi
call   1040 <sprintf@plt>
movb   $0x30,0x5(%rsp)
jmp    11a5 <convert_date+0x85>
lea    0x5(%rsp),%rdi
call   1040 <sprintf@plt>
imul   $0x2710,0x8(%rbx),%eax
imul   $0x64,(%rbx),%ecx
add    %eax,%ecx
mov    0x4(%rbx),%eax
add    %ecx,%eax
add    $0x121eb24,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i64 }
@.str = [3 x i8] c"%d\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @convert_date(%struct.tm* %0) {
%2 = alloca %struct.tm*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i8]
%6 = alloca [5 x i8]
%7 = alloca [3 x i8]
%8 = alloca [3 x i8]
store %struct.tm* %0, %struct.tm** %2
store i32 0, i32* %3
store i32 0, i32* %4
%9 = bitcast [2 x i8]* %5 to i8*
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* %3
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %3
%13 = load %struct.tm*, %struct.tm** %2
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 10
br i1 %18, label %19, label %28
19: ; preds = %1
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
store i8 48, i8* %23
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%25 = load i8, i8* %24
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 1
store i8 %25, i8* %26
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 2
store i8 0, i8* %27
br label %32
28: ; preds = %1
%29 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%30 = load i32, i32* %3
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %28, %19
%33 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%34 = call i32 @strncpy(i8* %33, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 3)
%35 = load %struct.tm*, %struct.tm** %2
%36 = getelementptr inbounds %struct.tm, %struct.tm* %35, i32 0, i32 1
%37 = load i32, i32* %36
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = icmp slt i32 %38, 10
br i1 %39, label %40, label %49
40: ; preds = %32
%41 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%42 = load i32, i32* %3
%43 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
store i8 48, i8* %44
%45 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%46 = load i8, i8* %45
%47 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
store i8 %46, i8* %47
%48 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 2
store i8 0, i8* %48
br label %53
49: ; preds = %32
%50 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%51 = load i32, i32* %3
%52 = call i32 @sprintf(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %49, %40
%54 = load %struct.tm*, %struct.tm** %2
%55 = getelementptr inbounds %struct.tm, %struct.tm* %54, i32 0, i32 2
%56 = load i64, i64* %55
%57 = trunc i64 %56 to i32
%58 = add nsw i32 %57, 1900
%59 = mul nsw i32 %58, 10000
%60 = load %struct.tm*, %struct.tm** %2
%61 = getelementptr inbounds %struct.tm, %struct.tm* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = add nsw i32 %62, 1
%64 = mul nsw i32 %63, 100
%65 = add nsw i32 %59, %64
%66 = load %struct.tm*, %struct.tm** %2
%67 = getelementptr inbounds %struct.tm, %struct.tm* %66, i32 0, i32 1
%68 = load i32, i32* %67
%69 = add nsw i32 %65, %68
store i32 %69, i32* %4
%70 = load i32, i32* %4
ret i32 %70
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i64 }
@.str = [3 x i8] c"%d\00"
@.str.1 = [1 x i8] zeroinitializer
define i32 @convert_date(%struct.tm* nocapture %0) {
%2 = alloca i16
%3 = alloca [5 x i8]
%4 = alloca [3 x i8]
%5 = alloca [3 x i8]
%6 = bitcast i16* %2 to i8*
store i16 0, i16* %2
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%10 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 0)
%11 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1
%14 = icmp slt i32 %12, 9
%15 = select i1 %14, i8* %6, i8* %8
%16 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%17 = call i32 @strncpy(i8* %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 3)
%18 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%19 = load i32, i32* %18
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
store i8 48, i8* %9
br label %25
23: ; preds = %1
%24 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %25
25: ; preds = %23, %21
%26 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%27 = load i64, i64* %26
%28 = trunc i64 %27 to i32
%29 = mul i32 %28, 10000
%30 = load i32, i32* %11
%31 = mul i32 %30, 100
%32 = load i32, i32* %18
%33 = add i32 %31, 19000100
%34 = add i32 %33, %29
%35 = add i32 %34, %32
ret i32 %35
}