#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 char wchar_t;
typedef int time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
struct tm *localtime(int *);
int /*<<< orphan*/ printf(char *, ...);
char *setlocale(int /*<<< orphan*/, char *);
size_t wcsftime(char *, int, char *, struct tm *);
int main(void) {
  wchar_t buf[256];
  struct tm *tp;
  time_t time_list[7] = {500,       68200000,  694223999, 694224000,
                         704900000, 705000000, 705900000};
  char *locale_list[3] = {"C", "fr_FR.ISO-8859-1", "ja_JP.UTF-8"};
  int result = 0, ddd, lll;
  size_t n;
  for (lll = 0; lll < 3; lll++) {
    printf("\nUsing locale: %s\n", locale_list[lll]);
    char *set = setlocale(LC_ALL, locale_list[lll]);
    if (set == NULL) {
      printf("FAILED!\n\n");
      continue;
    } else
      printf("\n");
    for (ddd = 0; ddd < 7; ddd++) {
      tp = localtime(&time_list[ddd]);
      printf("%ld corresponds to ", time_list[ddd]);
      n = wcsftime(buf, sizeof(buf) / sizeof(buf[0]), L"%H:%M:%S  %Y-%m-%d%n",
                   tp);
      if (n != 21) {
        result = 1;
        printf("FAILED!\n");
      }
      printf("%ls", buf);
      wcsftime(buf, sizeof(buf) / sizeof(buf[0]), L"%tor, as %%D %%T: %D %T%n",
               tp);
      printf("%ls", buf);
      wcsftime(buf, sizeof(buf) / sizeof(buf[0]), L"%A (%a)%n", tp);
      printf("The weekday was %ls", buf);
      wcsftime(buf, sizeof(buf) / sizeof(buf[0]), L"%B (%b) %Y%n", tp);
      printf("Month was %ls", buf);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x140(%rbp)
mov    0xea1(%rip),%rax
mov    %rax,-0x138(%rbp)
mov    0xe9b(%rip),%rax
mov    %rax,-0x130(%rbp)
mov    0xe96(%rip),%eax
mov    %eax,-0x128(%rbp)
mov    0x2c71(%rip),%rax
mov    %rax,-0x160(%rbp)
mov    0x2c6b(%rip),%rax
mov    %rax,-0x158(%rbp)
mov    0x2c65(%rip),%rax
mov    %rax,-0x150(%rbp)
movl   $0x0,-0x164(%rbp)
movl   $0x0,-0x16c(%rbp)
cmpl   $0x3,-0x16c(%rbp)
jge    13c1 <main+0x281>
movslq -0x16c(%rbp),%rax
mov    -0x160(%rbp,%rax,8),%rsi
ff
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
movslq -0x16c(%rbp),%rax
mov    -0x160(%rbp,%rax,8),%rsi
ff
call   1060 <setlocale@plt>
mov    %rax,-0x180(%rbp)
cmpq   $0x0,-0x180(%rbp)
jne    1235 <main+0xf5>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13ad <main+0x26d>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x168(%rbp)
cmpl   $0x7,-0x168(%rbp)
jge    13a8 <main+0x268>
movslq -0x168(%rbp),%rax
lea    -0x140(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x118(%rbp)
movslq -0x168(%rbp),%rax
mov    -0x140(%rbp,%rax,4),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rcx
mov    $0x100,%esi
lea    0xde7(%rip),%rdx
call   1040 <wcsftime@plt>
mov    %rax,-0x178(%rbp)
cmpq   $0x15,-0x178(%rbp)
15
je     12e3 <main+0x1a3>
movl   $0x1,-0x164(%rbp)
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rcx
mov    $0x100,%esi
lea    0xdda(%rip),%rdx
call   1040 <wcsftime@plt>
lea    -0x110(%rbp),%rsi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rcx
mov    $0x100,%esi
lea    0xe0e(%rip),%rdx
call   1040 <wcsftime@plt>
lea    -0x110(%rbp),%rsi
lea    0xd1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rcx
mov    $0x100,%esi
lea    0xe02(%rip),%rdx
call   1040 <wcsftime@plt>
lea    -0x110(%rbp),%rsi
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x168(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x168(%rbp)
jmp    124d <main+0x10d>
jmp    13ad <main+0x26d>
mov    -0x16c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x16c(%rbp)
jmp    11c6 <main+0x86>
mov    -0x164(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
movups 0xe94(%rip),%xmm0
movups %xmm0,0x1c(%rsp)
movaps 0xe7c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x30(%rsp),%rbx
lea    0xeeb(%rip),%r14
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    11bf <main+0x5f>
nopl   0x0(%rax)
lea    0xee5(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rsp),%rbp
add    $0x1,%rbp
cmp    $0x3,%rbp
je     12f6 <main+0x196>
lea    0x2c3a(%rip),%rax
mov    (%rax,%rbp,8),%r12
lea    0xe6a(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
call   1080 <setlocale@plt>
test   %rax,%rax
mov    %rbp,0x8(%rsp)
je     11a0 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r13d,%r13d
lea    0xe6c(%rip),%rbp
jmp    129b <main+0x13b>
nop
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
lea    0xec0(%rip),%rdx
mov    %r12,%rcx
call   1060 <wcsftime@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
lea    0xf04(%rip),%rdx
mov    %r12,%rcx
call   1060 <wcsftime@plt>
lea    0xe03(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
lea    0xf04(%rip),%rdx
mov    %r12,%rcx
call   1060 <wcsftime@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x4,%r13
cmp    $0x1c,%r13
je     11ac <main+0x4c>
lea    (%rsp,%r13,1),%rdi
add    $0x10,%rdi
call   1040 <localtime@plt>
mov    %rax,%r12
mov    0x10(%rsp,%r13,1),%esi
lea    0xd97(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
lea    0xdcb(%rip),%rdx
mov    %r12,%rcx
call   1060 <wcsftime@plt>
cmp    $0x15,%rax
je     1210 <main+0xb0>
lea    0xd9e(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%r15d
jmp    1210 <main+0xb0>
mov    %r15d,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@__const.main.time_list = [7 x i32] [i32 500, i32 68200000, i32 694223999, i32 694224000, i32 704900000, i32 705000000, i32 705900000]
@.str = [2 x i8] c"C\00"
@.str.1 = [17 x i8] c"fr_FR.ISO-8859-1\00"
@.str.2 = [12 x i8] c"ja_JP.UTF-8\00"
@__const.main.locale_list = [3 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [19 x i8] c"\0AUsing locale: %s\0A\00"
@LC_ALL = global i32 0
@.str.4 = [10 x i8] c"FAILED!\0A\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [20 x i8] c"%ld corresponds to \00"
@.str.7 = [21 x i32] [i32 37, i32 72, i32 58, i32 37, i32 77, i32 58, i32 37, i32 83, i32 32, i32 32, i32 37, i32 89, i32 45, i32 37, i32 109, i32 45, i32 37, i32 100, i32 37, i32 110, i32 0]
@.str.8 = [9 x i8] c"FAILED!\0A\00"
@.str.9 = [4 x i8] c"%ls\00"
@.str.10 = [26 x i32] [i32 37, i32 116, i32 111, i32 114, i32 44, i32 32, i32 97, i32 115, i32 32, i32 37, i32 37, i32 68, i32 32, i32 37, i32 37, i32 84, i32 58, i32 32, i32 37, i32 68, i32 32, i32 37, i32 84, i32 37, i32 110, i32 0]
@.str.11 = [10 x i32] [i32 37, i32 65, i32 32, i32 40, i32 37, i32 97, i32 41, i32 37, i32 110, i32 0]
@.str.12 = [20 x i8] c"The weekday was %ls\00"
@.str.13 = [13 x i32] [i32 37, i32 66, i32 32, i32 40, i32 37, i32 98, i32 41, i32 32, i32 37, i32 89, i32 37, i32 110, i32 0]
@.str.14 = [14 x i8] c"Month was %ls\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca %struct.tm*
%4 = alloca [7 x i32]
%5 = alloca [3 x i8*]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
store i32 0, i32* %1
%11 = bitcast [7 x i32]* %4 to i8*
%12 = bitcast [3 x i8*]* %5 to i8*
store i32 0, i32* %6
store i32 0, i32* %8
br label %13
13: ; preds = %77, %0
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %80
16: ; preds = %13
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @LC_ALL
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i8* @setlocale(i32 %22, i8* %26)
store i8* %27, i8** %10
%28 = load i8*, i8** %10
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %16
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %77
32: ; preds = %16
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %32
store i32 0, i32* %7
br label %35
35: ; preds = %73, %34
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 7
br i1 %37, label %38, label %76
38: ; preds = %35
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [7 x i32], [7 x i32]* %4, i64 0, i64 %40
%42 = call %struct.tm* @localtime(i32* %41)
store %struct.tm* %42, %struct.tm** %3
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [7 x i32], [7 x i32]* %4, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%49 = load %struct.tm*, %struct.tm** %3
%50 = call i64 @wcsftime(i8* %48, i32 256, i8* bitcast ([21 x i32]* @.str.7 to i8*), %struct.tm* %49)
store i64 %50, i64* %9
%51 = load i64, i64* %9
%52 = icmp ne i64 %51, 21
br i1 %52, label %53, label %55
53: ; preds = %38
store i32 1, i32* %6
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %55
55: ; preds = %53, %38
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %56)
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%59 = load %struct.tm*, %struct.tm** %3
%60 = call i64 @wcsftime(i8* %58, i32 256, i8* bitcast ([26 x i32]* @.str.10 to i8*), %struct.tm* %59)
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %61)
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%64 = load %struct.tm*, %struct.tm** %3
%65 = call i64 @wcsftime(i8* %63, i32 256, i8* bitcast ([10 x i32]* @.str.11 to i8*), %struct.tm* %64)
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* %66)
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%69 = load %struct.tm*, %struct.tm** %3
%70 = call i64 @wcsftime(i8* %68, i32 256, i8* bitcast ([13 x i32]* @.str.13 to i8*), %struct.tm* %69)
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i64 0, i64 0), i8* %71)
br label %73
73: ; preds = %55
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
br label %35
76: ; preds = %35
br label %77
77: ; preds = %76, %30
%78 = load i32, i32* %8
%79 = add nsw i32 %78, 1
store i32 %79, i32* %8
br label %13
80: ; preds = %13
%81 = load i32, i32* %6
ret i32 %81
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@__const.main.time_list = [7 x i32] [i32 500, i32 68200000, i32 694223999, i32 694224000, i32 704900000, i32 705000000, i32 705900000]
@.str = [2 x i8] c"C\00"
@.str.1 = [17 x i8] c"fr_FR.ISO-8859-1\00"
@.str.2 = [12 x i8] c"ja_JP.UTF-8\00"
@__const.main.locale_list = [3 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [19 x i8] c"\0AUsing locale: %s\0A\00"
@LC_ALL = global i32 0
@.str.6 = [20 x i8] c"%ld corresponds to \00"
@.str.7 = [21 x i32] [i32 37, i32 72, i32 58, i32 37, i32 77, i32 58, i32 37, i32 83, i32 32, i32 32, i32 37, i32 89, i32 45, i32 37, i32 109, i32 45, i32 37, i32 100, i32 37, i32 110, i32 0]
@.str.9 = [4 x i8] c"%ls\00"
@.str.10 = [26 x i32] [i32 37, i32 116, i32 111, i32 114, i32 44, i32 32, i32 97, i32 115, i32 32, i32 37, i32 37, i32 68, i32 32, i32 37, i32 37, i32 84, i32 58, i32 32, i32 37, i32 68, i32 32, i32 37, i32 84, i32 37, i32 110, i32 0]
@.str.11 = [10 x i32] [i32 37, i32 65, i32 32, i32 40, i32 37, i32 97, i32 41, i32 37, i32 110, i32 0]
@.str.12 = [20 x i8] c"The weekday was %ls\00"
@.str.13 = [13 x i32] [i32 37, i32 66, i32 32, i32 40, i32 37, i32 98, i32 41, i32 32, i32 37, i32 89, i32 37, i32 110, i32 0]
@.str.14 = [14 x i8] c"Month was %ls\00"
@str = [8 x i8] c"FAILED!\00"
@str.15 = [9 x i8] c"FAILED!\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca [7 x i32]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast [7 x i32]* %2 to i8*
br label %5
5: ; preds = %0, %40
%6 = phi i64 [ 0, %0 ], [ %42, %40 ]
%7 = phi i32 [ 0, %0 ], [ %41, %40 ]
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.main.locale_list, i64 0, i64 %6
%9 = load i8*, i8** %8
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @LC_ALL
%12 = call i8* @setlocale(i32 %11, i8* %9)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.15, i64 0, i64 0))
br label %40
16: ; preds = %5
%17 = call i32 @putchar(i32 10)
br label %18
18: ; preds = %16, %29
%19 = phi i64 [ 0, %16 ], [ %38, %29 ]
%20 = phi i32 [ %7, %16 ], [ %30, %29 ]
%21 = getelementptr inbounds [7 x i32], [7 x i32]* %2, i64 0, i64 %19
%22 = call %struct.tm* @localtime(i32* %21)
%23 = load i32, i32* %21
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %23)
%25 = call i64 @wcsftime(i8* %3, i32 256, i8* bitcast ([21 x i32]* @.str.7 to i8*), %struct.tm* %22)
%26 = icmp eq i64 %25, 21
br i1 %26, label %29, label %27
27: ; preds = %18
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %29
29: ; preds = %27, %18
%30 = phi i32 [ 1, %27 ], [ %20, %18 ]
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %3)
%32 = call i64 @wcsftime(i8* %3, i32 256, i8* bitcast ([26 x i32]* @.str.10 to i8*), %struct.tm* %22)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %3)
%34 = call i64 @wcsftime(i8* %3, i32 256, i8* bitcast ([10 x i32]* @.str.11 to i8*), %struct.tm* %22)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* %3)
%36 = call i64 @wcsftime(i8* %3, i32 256, i8* bitcast ([13 x i32]* @.str.13 to i8*), %struct.tm* %22)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i64 0, i64 0), i8* %3)
%38 = add nuw nsw i64 %19, 1
%39 = icmp eq i64 %38, 7
br i1 %39, label %40, label %18
40: ; preds = %29, %14
%41 = phi i32 [ %7, %14 ], [ %30, %29 ]
%42 = add nuw nsw i64 %6, 1
%43 = icmp eq i64 %42, 3
br i1 %43, label %44, label %5
44: ; preds = %40
ret i32 %41
}