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

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
char *setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char toupper(int /*<<< orphan*/);
char *__attribute__((unused)) upstr(char *dst, const char *str) {
  char *cp = dst;
  char old_locale[20], *old_locale_p;
  old_locale_p = setlocale(LC_ALL, "C");
  strncpy(old_locale, old_locale_p, 20);
  while ((*cp++ = toupper(*str++)) != '\0')
    ;
  setlocale(LC_ALL, old_locale);
  return dst;
}


x86 assembly (clang, -O0):
<upstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
call   1050 <setlocale@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
je     11ac <upstr+0x7c>
jmp    1173 <upstr+0x43>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1050 <setlocale@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upstr>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
mov    0x2e98(%rip),%r15
mov    (%r15),%edi
lea    0xeae(%rip),%rsi
call   1050 <setlocale@plt>
mov    %rsp,%rdi
mov    %rax,%rsi
mov    $0x14,%edx
call   1030 <strncpy@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r12,%rbx,1),%edi
call   1040 <toupper@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
test   %al,%al
jne    1170 <upstr+0x40>
mov    (%r15),%edi
mov    %rsp,%rsi
call   1050 <setlocale@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [2 x i8] c"C\00"
define i8* @upstr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [20 x i8]
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i32, i32* @LC_ALL
%10 = call i8* @setlocale(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %7
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %7
%13 = call i32 @strncpy(i8* %11, i8* %12, i32 20)
br label %14
14: ; preds = %24, %2
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %4
%17 = load i8, i8* %15
%18 = sext i8 %17 to i32
%19 = call signext i8 @toupper(i32 %18)
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
store i8 %19, i8* %20
%22 = sext i8 %19 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %14
br label %14
25: ; preds = %14
%26 = load i32, i32* @LC_ALL
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%28 = call i8* @setlocale(i32 %26, i8* %27)
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [2 x i8] c"C\00"
define i8* @upstr(i8* returned writeonly %0, i8* nocapture %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @LC_ALL
%6 = tail call i8* @setlocale(i32 %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @strncpy(i8* %4, i8* %6, i32 20)
br label %8
8: ; preds = %8, %2
%9 = phi i8* [ %0, %2 ], [ %15, %8 ]
%10 = phi i8* [ %1, %2 ], [ %11, %8 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
%13 = sext i8 %12 to i32
%14 = call signext i8 @toupper(i32 %13)
%15 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %14, i8* %9
%16 = icmp eq i8 %14, 0
br i1 %16, label %17, label %8
17: ; preds = %8
%18 = load i32, i32* @LC_ALL
%19 = call i8* @setlocale(i32 %18, i8* %4)
ret i8* %0
}