#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;
};

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ printf(char *, char *, int, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ *setlocale(int /*<<< orphan*/, char *);
char *strptime(char const *, char *, struct tm *);
int do_test(void) {
  if (setlocale(LC_ALL, "vi_VN.TCVN5712-1") == NULL) {
    puts("cannot set locale");
    return 1;
  }
  struct tm tm;
  static const char s[] =
      "\x54\x68\xb8\x6e\x67\x20\x6d\xad\xea\x69\x20\x6d\xe9\x74";
  char *r = strptime(s, "%b", &tm);
  printf("r = %p, r-s = %tu, tm.tm_mon = %d\n", r, r - s, tm.tm_mon);
  return r == NULL || r - s != 14 || tm.tm_mon != 10;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
call   1050 <setlocale@plt>
cmp    $0x0,%rax
jne    117f <do_test+0x3f>
lea    0xea3(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ff <do_test+0xbf>
lea    0xec3(%rip),%rdi
lea    0xe96(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1060 <strptime@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
lea    0xea0(%rip),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    -0x8(%rbp),%ecx
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%al
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     11f4 <do_test+0xb4>
mov    -0x10(%rbp),%rcx
lea    0xe71(%rip),%rax
sub    %rax,%rcx
mov    $0x1,%al
cmp    $0xe,%rcx
mov    %al,-0x11(%rbp)
jne    11f4 <do_test+0xb4>
cmpl   $0xa,-0x8(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
call   1050 <setlocale@plt>
test   %rax,%rax
je     11ba <do_test+0x7a>
lea    0xedf(%rip),%r14
lea    0xeb2(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
call   1060 <strptime@plt>
mov    %rax,%r15
mov    %rax,%rbx
sub    %r14,%rbx
mov    0x8(%rsp),%ecx
lea    0xe94(%rip),%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1040 <printf@plt>
test   %r15,%r15
sete   %al
cmp    $0xe,%rbx
setne  %cl
cmpl   $0xa,0x8(%rsp)
setne  %dl
or     %al,%cl
or     %dl,%cl
movzbl %cl,%eax
jmp    11cb <do_test+0x8b>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@LC_ALL = global i32 0
@.str = [17 x i8] c"vi_VN.TCVN5712-1\00"
@.str.1 = [18 x i8] c"cannot set locale\00"
@do_test.s = internal constant [15 x i8] c"Th\B8ng m\AD\EAi m\E9t\00"
@.str.2 = [3 x i8] c"%b\00"
@.str.3 = [35 x i8] c"r = %p, r-s = %tu, tm.tm_mon = %d\0A\00"
define i32 @do_test() {
%1 = alloca i32
%2 = alloca %struct.tm
%3 = alloca i8*
%4 = load i32, i32* @LC_ALL
%5 = call i32* @setlocale(i32 %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %33
9: ; preds = %0
%10 = call i8* @strptime(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @do_test.s, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %2)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = load i8*, i8** %3
%13 = ptrtoint i8* %12 to i64
%14 = sub i64 %13, ptrtoint ([15 x i8]* @do_test.s to i64)
%15 = trunc i64 %14 to i32
%16 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %11, i32 %15, i32 %17)
%19 = load i8*, i8** %3
%20 = icmp eq i8* %19, null
br i1 %20, label %30, label %21
21: ; preds = %9
%22 = load i8*, i8** %3
%23 = ptrtoint i8* %22 to i64
%24 = sub i64 %23, ptrtoint ([15 x i8]* @do_test.s to i64)
%25 = icmp ne i64 %24, 14
br i1 %25, label %30, label %26
26: ; preds = %21
%27 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 0
%28 = load i32, i32* %27
%29 = icmp ne i32 %28, 10
br label %30
30: ; preds = %26, %21, %9
%31 = phi i1 [ true, %21 ], [ true, %9 ], [ %29, %26 ]
%32 = zext i1 %31 to i32
store i32 %32, i32* %1
br label %33
33: ; preds = %30, %7
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@LC_ALL = global i32 0
@.str = [17 x i8] c"vi_VN.TCVN5712-1\00"
@.str.1 = [18 x i8] c"cannot set locale\00"
@do_test.s = internal constant [15 x i8] c"Th\B8ng m\AD\EAi m\E9t\00"
@.str.2 = [3 x i8] c"%b\00"
@.str.3 = [35 x i8] c"r = %p, r-s = %tu, tm.tm_mon = %d\0A\00"
define i32 @do_test() {
%1 = alloca %struct.tm
%2 = load i32, i32* @LC_ALL
%3 = tail call i32* @setlocale(i32 %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %23
7: ; preds = %0
%8 = bitcast %struct.tm* %1 to i8*
%9 = call i8* @strptime(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @do_test.s, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %1)
%10 = ptrtoint i8* %9 to i64
%11 = sub i64 %10, ptrtoint ([15 x i8]* @do_test.s to i64)
%12 = trunc i64 %11 to i32
%13 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %9, i32 %12, i32 %14)
%16 = icmp eq i8* %9, null
%17 = icmp ne i64 %11, 14
%18 = load i32, i32* %13
%19 = icmp ne i32 %18, 10
%20 = or i1 %16, %17
%21 = select i1 %20, i1 true, i1 %19
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %7, %5
%24 = phi i32 [ 1, %5 ], [ %22, %7 ]
ret i32 %24
}