#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_sec;
  int tm_min;
  int tm_hour;
  int tm_mday;
  int tm_mon;
  int tm_year;
  int tm_wday;
  int tm_yday;
  int tm_isdst;
};

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int, int, int,
                            int, int, int);
char *tm_str(struct tm tm) {
  static int i;
  static char b[4][64];
  i = (i + 1) % 4;
  snprintf(b[i], sizeof b[i],
           "s=%.2d m=%.2d h=%.2d mday=%.2d mon=%.2d year=%.4d wday=%d yday=%d "
           "isdst=%d",
           tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, tm.tm_mon, tm.tm_year,
           tm.tm_wday, tm.tm_yday, tm.tm_isdst);
  return b[i];
}


x86 assembly (clang, -O0):
<tm_str>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2f15(%rip),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
mov    %edx,0x2f00(%rip)
movslq 0x2ef9(%rip),%rcx
lea    0x2f02(%rip),%rdi
shl    $0x6,%rcx
add    %rcx,%rdi
mov    (%rax),%ecx
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
mov    0xc(%rax),%r15d
mov    0x10(%rax),%r14d
mov    0x14(%rax),%ebx
mov    0x18(%rax),%r11d
mov    0x1c(%rax),%r10d
mov    0x20(%rax),%eax
mov    $0x40,%esi
lea    0xe7f(%rip),%rdx
mov    %r15d,(%rsp)
mov    %r14d,0x8(%rsp)
mov    %ebx,0x10(%rsp)
mov    %r11d,0x18(%rsp)
mov    %r10d,0x20(%rsp)
mov    %eax,0x28(%rsp)
call   1030 <snprintf@plt>
movslq 0x2e98(%rip),%rcx
lea    0x2ea1(%rip),%rax
shl    $0x6,%rcx
add    %rcx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2f22(%rip),%eax
lea    0x1(%rax),%ecx
lea    0x4(%rax),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
and    $0xfffffffc,%edx
neg    %edx
lea    (%rax,%rdx,1),%edi
add    $0x1,%edi
mov    %edi,0x2f06(%rip)
shl    $0x6,%rdi
lea    0x2f0b(%rip),%r14
add    %r14,%rdi
mov    0x30(%rsp),%ecx
mov    0x34(%rsp),%r8d
mov    0x38(%rsp),%r9d
mov    0x3c(%rsp),%r10d
mov    0x40(%rsp),%r11d
mov    0x44(%rsp),%r15d
mov    0x48(%rsp),%r12d
mov    0x4c(%rsp),%eax
mov    0x50(%rsp),%ebx
lea    0xe87(%rip),%rdx
mov    $0x40,%esi
push   %rbx
push   %rax
push   %r12
push   %r15
push   %r11
push   %r10
call   1030 <snprintf@plt>
add    $0x30,%rsp
mov    0x2ea9(%rip),%eax
shl    $0x6,%rax
add    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }
@tm_str.i = internal global i32 0
@tm_str.b = internal global [4 x [64 x i8]] zeroinitializer
@.str = [75 x i8] c"s=%.2d m=%.2d h=%.2d mday=%.2d mon=%.2d year=%.4d wday=%d yday=%d isdst=%d\00"
define i8* @tm_str(%struct.tm* byval(%struct.tm) align 8 %0) {
%2 = load i32, i32* @tm_str.i
%3 = add nsw i32 %2, 1
%4 = srem i32 %3, 4
store i32 %4, i32* @tm_str.i
%5 = load i32, i32* @tm_str.i
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [4 x [64 x i8]], [4 x [64 x i8]]* @tm_str.b, i64 0, i64 %6
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%9 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 2
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 3
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 4
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 5
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 6
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 7
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %0, i32 0, i32 8
%26 = load i32, i32* %25
%27 = call i32 @snprintf(i8* %8, i32 64, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %12, i32 %14, i32 %16, i32 %18, i32 %20, i32 %22, i32 %24, i32 %26)
%28 = load i32, i32* @tm_str.i
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [4 x [64 x i8]], [4 x [64 x i8]]* @tm_str.b, i64 0, i64 %29
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %30, i64 0, i64 0
ret i8* %31
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }
@tm_str.i = internal unnamed_addr global i32 0
@tm_str.b = internal global [4 x [64 x i8]] zeroinitializer
@.str = [75 x i8] c"s=%.2d m=%.2d h=%.2d mday=%.2d mon=%.2d year=%.4d wday=%d yday=%d isdst=%d\00"
define i8* @tm_str(%struct.tm* nocapture byval(%struct.tm) align 8 %0) {
%2 = load i32, i32* @tm_str.i
%3 = add nsw i32 %2, 1
%4 = srem i32 %3, 4
store i32 %4, i32* @tm_str.i
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds [4 x [64 x i8]], [4 x [64 x i8]]* @tm_str.b, i64 0, i64 %5, i64 0
%7 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 2
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 3
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 4
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 5
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 6
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 7
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 8
%24 = load i32, i32* %23
%25 = tail call i32 @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10, i32 %12, i32 %14, i32 %16, i32 %18, i32 %20, i32 %22, i32 %24)
%26 = load i32, i32* @tm_str.i
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [4 x [64 x i8]], [4 x [64 x i8]]* @tm_str.b, i64 0, i64 %27, i64 0
ret i8* %28
}