#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 */
size_t strlen(char *);
char tolower(char);
char toupper(char);
void ulstr(int ul, char *b) {
  size_t i;
  switch (ul) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpointer-sign"
  case 'u':
    for (i = 0; i < strlen(b); i++) {
      b[i] = toupper(b[i]);
    }
    break;
  case 'l':
    for (i = 0; i < strlen(b); i++) {
      b[i] = tolower(b[i]);
    }
    break;
#pragma GCC diagnostic pop
  default:
    b[0] = 0;
    break;
  }
}


x86 assembly (clang, -O0):
<ulstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x6c,%eax
je     11c1 <ulstr+0x91>
jmp    1153 <ulstr+0x23>
mov    -0x1c(%rbp),%eax
sub    $0x75,%eax
jne    121e <ulstr+0xee>
jmp    1164 <ulstr+0x34>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jae    11bc <ulstr+0x8c>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    116c <ulstr+0x3c>
jmp    1225 <ulstr+0xf5>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jae    1219 <ulstr+0xe9>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <tolower@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11c9 <ulstr+0x99>
jmp    1225 <ulstr+0xf5>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ulstr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x75,%edi
je     11a1 <ulstr+0x71>
cmp    $0x6c,%edi
jne    11f1 <ulstr+0xc1>
mov    (%r14),%al
test   %al,%al
je     11f5 <ulstr+0xc5>
movsbl %al,%edi
call   1050 <tolower@plt>
mov    %al,(%r14)
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%rax
jb     11f5 <ulstr+0xc5>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%edi
call   1050 <tolower@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
jb     1180 <ulstr+0x50>
jmp    11f5 <ulstr+0xc5>
mov    (%r14),%al
test   %al,%al
je     11f5 <ulstr+0xc5>
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,(%r14)
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%rax
jb     11f5 <ulstr+0xc5>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
jb     11d0 <ulstr+0xa0>
jmp    11f5 <ulstr+0xc5>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @ulstr(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
switch i32 %6, label %45 [
i32 117, label %7
i32 108, label %26
]
7: ; preds = %2
store i64 0, i64* %5
br label %8
8: ; preds = %22, %7
%9 = load i64, i64* %5
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
%12 = icmp ult i64 %9, %11
br i1 %12, label %13, label %25
13: ; preds = %8
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
%18 = call signext i8 @toupper(i8 signext %17)
%19 = load i8*, i8** %4
%20 = load i64, i64* %5
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8 %18, i8* %21
br label %22
22: ; preds = %13
%23 = load i64, i64* %5
%24 = add i64 %23, 1
store i64 %24, i64* %5
br label %8
25: ; preds = %8
br label %48
26: ; preds = %2
store i64 0, i64* %5
br label %27
27: ; preds = %41, %26
%28 = load i64, i64* %5
%29 = load i8*, i8** %4
%30 = call i64 @strlen(i8* %29)
%31 = icmp ult i64 %28, %30
br i1 %31, label %32, label %44
32: ; preds = %27
%33 = load i8*, i8** %4
%34 = load i64, i64* %5
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i8, i8* %35
%37 = call signext i8 @tolower(i8 signext %36)
%38 = load i8*, i8** %4
%39 = load i64, i64* %5
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 %37, i8* %40
br label %41
41: ; preds = %32
%42 = load i64, i64* %5
%43 = add i64 %42, 1
store i64 %43, i64* %5
br label %27
44: ; preds = %27
br label %48
45: ; preds = %2
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i64 0
store i8 0, i8* %47
br label %48
48: ; preds = %45, %44, %25
ret void
}

LLVM IR (-O2):
define void @ulstr(i32 %0, i8* nocapture %1) {
switch i32 %0, label %35 [
i32 117, label %10
i32 108, label %3
]
3: ; preds = %2
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %36, label %6
6: ; preds = %3
%7 = tail call signext i8 @tolower(i8 signext %4)
store i8 %7, i8* %1
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = icmp ugt i64 %8, 1
br i1 %9, label %26, label %36
10: ; preds = %2
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 0
br i1 %12, label %36, label %13
13: ; preds = %10
%14 = tail call signext i8 @toupper(i8 signext %11)
store i8 %14, i8* %1
%15 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%16 = icmp ugt i64 %15, 1
br i1 %16, label %17, label %36
17: ; preds = %13, %17
%18 = phi i64 [ %23, %17 ], [ 1, %13 ]
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds i8, i8* %1, i64 %18
%22 = tail call signext i8 @toupper(i8 signext %20)
store i8 %22, i8* %21
%23 = add nuw i64 %18, 1
%24 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%25 = icmp ult i64 %23, %24
br i1 %25, label %17, label %36
26: ; preds = %6, %26
%27 = phi i64 [ %32, %26 ], [ 1, %6 ]
%28 = getelementptr inbounds i8, i8* %1, i64 %27
%29 = load i8, i8* %28
%30 = getelementptr inbounds i8, i8* %1, i64 %27
%31 = tail call signext i8 @tolower(i8 signext %29)
store i8 %31, i8* %30
%32 = add nuw i64 %27, 1
%33 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%34 = icmp ult i64 %32, %33
br i1 %34, label %26, label %36
35: ; preds = %2
store i8 0, i8* %1
br label %36
36: ; preds = %26, %17, %6, %13, %3, %10, %35
ret void
}