#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 scalar_t__ wchar_t;
struct dstr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ bfree(scalar_t__ *);
int /*<<< orphan*/ dstr_from_wcs(struct dstr *, scalar_t__ *);
scalar_t__ dstr_is_empty(struct dstr *);
scalar_t__ *dstr_to_wcs(struct dstr *);
scalar_t__ towupper(scalar_t__);
void dstr_to_upper(struct dstr *str) {
  wchar_t *wstr;
  wchar_t *temp;
  if (dstr_is_empty(str))
    return;
  wstr = dstr_to_wcs(str);
  temp = wstr;
  if (!wstr)
    return;
  while (*temp) {
    *temp = (wchar_t)towupper(*temp);
    temp++;
  }
  dstr_from_wcs(str, wstr);
  bfree(wstr);
}


x86 assembly (clang, -O0):
<dstr_to_upper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <dstr_is_empty@plt>
cmp    $0x0,%rax
je     1174 <dstr_to_upper+0x24>
jmp    11e9 <dstr_to_upper+0x99>
mov    -0x8(%rbp),%rdi
call   1030 <dstr_to_wcs@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <dstr_to_upper+0x49>
jmp    11e9 <dstr_to_upper+0x99>
jmp    119e <dstr_to_upper+0x4e>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11d3 <dstr_to_upper+0x83>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1070 <towupper@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    119e <dstr_to_upper+0x4e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <dstr_from_wcs@plt>
mov    -0x10(%rbp),%rdi
call   1050 <bfree@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dstr_to_upper>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1060 <dstr_is_empty@plt>
test   %rax,%rax
je     1168 <dstr_to_upper+0x18>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
call   1030 <dstr_to_wcs@plt>
test   %rax,%rax
je     1162 <dstr_to_upper+0x12>
mov    %rax,%r14
mov    (%rax),%rdi
test   %rdi,%rdi
je     11a5 <dstr_to_upper+0x55>
mov    %r14,%rbx
add    $0x8,%rbx
nopw   0x0(%rax,%rax,1)
call   1070 <towupper@plt>
mov    %rax,-0x8(%rbx)
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1190 <dstr_to_upper+0x40>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <dstr_from_wcs@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <bfree@plt>

LLVM IR (-O0):
%struct.dstr = type { i32 }
define void @dstr_to_upper(%struct.dstr* %0) {
%2 = alloca %struct.dstr*
%3 = alloca i64*
%4 = alloca i64*
store %struct.dstr* %0, %struct.dstr** %2
%5 = load %struct.dstr*, %struct.dstr** %2
%6 = call i64 @dstr_is_empty(%struct.dstr* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
br label %34
9: ; preds = %1
%10 = load %struct.dstr*, %struct.dstr** %2
%11 = call i64* @dstr_to_wcs(%struct.dstr* %10)
store i64* %11, i64** %3
%12 = load i64*, i64** %3
store i64* %12, i64** %4
%13 = load i64*, i64** %3
%14 = icmp ne i64* %13, null
br i1 %14, label %16, label %15
15: ; preds = %9
br label %34
16: ; preds = %9
br label %17
17: ; preds = %21, %16
%18 = load i64*, i64** %4
%19 = load i64, i64* %18
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i64*, i64** %4
%23 = load i64, i64* %22
%24 = call i64 @towupper(i64 %23)
%25 = load i64*, i64** %4
store i64 %24, i64* %25
%26 = load i64*, i64** %4
%27 = getelementptr inbounds i64, i64* %26, i32 1
store i64* %27, i64** %4
br label %17
28: ; preds = %17
%29 = load %struct.dstr*, %struct.dstr** %2
%30 = load i64*, i64** %3
%31 = call i32 @dstr_from_wcs(%struct.dstr* %29, i64* %30)
%32 = load i64*, i64** %3
%33 = call i32 @bfree(i64* %32)
br label %34
34: ; preds = %28, %15, %8
ret void
}

LLVM IR (-O2):
%struct.dstr = type { i32 }
define void @dstr_to_upper(%struct.dstr* %0) {
%2 = tail call i64 @dstr_is_empty(%struct.dstr* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %20
4: ; preds = %1
%5 = tail call i64* @dstr_to_wcs(%struct.dstr* %0)
%6 = icmp eq i64* %5, null
br i1 %6, label %20, label %7
7: ; preds = %4
%8 = load i64, i64* %5
%9 = icmp eq i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %7, %10
%11 = phi i64 [ %15, %10 ], [ %8, %7 ]
%12 = phi i64* [ %14, %10 ], [ %5, %7 ]
%13 = tail call i64 @towupper(i64 %11)
store i64 %13, i64* %12
%14 = getelementptr inbounds i64, i64* %12, i64 1
%15 = load i64, i64* %14
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %10
17: ; preds = %10, %7
%18 = tail call i32 @dstr_from_wcs(%struct.dstr* %0, i64* %5)
%19 = tail call i32 @bfree(i64* %5)
br label %20
20: ; preds = %4, %1, %17
ret void
}