#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 */
scalar_t__ somefunc1(int, int);
const char *dothings(char opt) {
  opt += somefunc1(opt, 2);
  char *msg;
  switch (opt) {
  case 'a':
    msg = "Got a";
    break;
  case 'b':
    msg = "Got b";
    break;
  case '\0':
    msg = "For serious?";
    break;
  default:
    msg = "Unknown command";
  }
  for (int i = 0; i < 5; i++) {
    if (opt == 'a') {
      opt += somefunc1(i, 4);
    } else if (opt == 'b') {
      opt += somefunc1(i, 5);
    } else {
      opt += somefunc1(i, 6);
    }
  }
  msg[0] = opt;
  return msg;
}


x86 assembly (clang, -O0):
<dothings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%edi
mov    $0x2,%esi
call   1030 <somefunc1@plt>
mov    %rax,%rcx
movzbl -0x1(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
mov    %eax,-0x18(%rbp)
test   %eax,%eax
je     118e <dothings+0x7e>
jmp    114c <dothings+0x3c>
mov    -0x18(%rbp),%eax
sub    $0x61,%eax
je     116e <dothings+0x5e>
jmp    115d <dothings+0x4d>
mov    -0x18(%rbp),%eax
sub    $0x62,%eax
je     117e <dothings+0x6e>
jmp    119e <dothings+0x8e>
lea    0xe8b(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11a9 <dothings+0x99>
lea    0xe81(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11a9 <dothings+0x99>
lea    0xe77(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11a9 <dothings+0x99>
lea    0xe74(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    1247 <dothings+0x137>
movsbl -0x1(%rbp),%eax
cmp    $0x61,%eax
jne    11e7 <dothings+0xd7>
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1030 <somefunc1@plt>
mov    %rax,%rcx
movsbq -0x1(%rbp),%rax
add    %rcx,%rax
mov    %al,-0x1(%rbp)
jmp    1234 <dothings+0x124>
movsbl -0x1(%rbp),%eax
cmp    $0x62,%eax
jne    1214 <dothings+0x104>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1030 <somefunc1@plt>
mov    %rax,%rcx
movsbq -0x1(%rbp),%rax
add    %rcx,%rax
mov    %al,-0x1(%rbp)
jmp    122f <dothings+0x11f>
mov    -0x14(%rbp),%edi
mov    $0x6,%esi
call   1030 <somefunc1@plt>
mov    %rax,%rcx
movsbq -0x1(%rbp),%rax
add    %rcx,%rax
mov    %al,-0x1(%rbp)
jmp    1234 <dothings+0x124>
jmp    1239 <dothings+0x129>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b0 <dothings+0xa0>
mov    -0x1(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dothings>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebp
mov    $0x2,%esi
call   1030 <somefunc1@plt>
mov    %rax,%rbx
add    %bpl,%bl
movsbl %bl,%eax
test   %eax,%eax
je     1144 <dothings+0x34>
cmp    $0x61,%eax
je     114d <dothings+0x3d>
cmp    $0x62,%eax
jne    1156 <dothings+0x46>
lea    0xec4(%rip),%r14
jmp    115d <dothings+0x4d>
lea    0xec1(%rip),%r14
jmp    115d <dothings+0x4d>
lea    0xeac(%rip),%r14
jmp    115d <dothings+0x4d>
lea    0xebc(%rip),%r14
xor    %eax,%eax
cmp    $0x62,%bl
sete   %al
mov    $0x6,%r15d
mov    $0x6,%esi
sub    %eax,%esi
cmp    $0x61,%bl
mov    $0x4,%r12d
cmove  %r12d,%esi
xor    %edi,%edi
call   1030 <somefunc1@plt>
mov    %rax,%rbp
add    %bl,%bpl
xor    %eax,%eax
cmp    $0x62,%bpl
sete   %al
mov    $0x6,%esi
sub    %eax,%esi
cmp    $0x61,%bpl
cmove  %r12d,%esi
mov    $0x1,%edi
call   1030 <somefunc1@plt>
mov    %rax,%rbx
add    %bpl,%bl
xor    %eax,%eax
cmp    $0x62,%bl
sete   %al
mov    $0x6,%esi
sub    %eax,%esi
cmp    $0x61,%bl
cmove  %r12d,%esi
mov    $0x2,%edi
call   1030 <somefunc1@plt>
mov    %rax,%rbp
add    %bl,%bpl
xor    %eax,%eax
cmp    $0x62,%bpl
sete   %al
mov    $0x6,%esi
sub    %eax,%esi
cmp    $0x61,%bpl
cmove  %r12d,%esi
mov    $0x3,%edi
call   1030 <somefunc1@plt>
add    %bpl,%al
xor    %ecx,%ecx
cmp    $0x62,%al
sete   %cl
sub    %ecx,%r15d
cmp    $0x61,%al
cmove  %r12d,%r15d
mov    $0x4,%edi
mov    %r15d,%esi
call   1030 <somefunc1@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Got a\00"
@.str.1 = [6 x i8] c"Got b\00"
@.str.2 = [13 x i8] c"For serious?\00"
@.str.3 = [16 x i8] c"Unknown command\00"
define i8* @dothings(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32
store i8 %0, i8* %2
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = call i64 @somefunc1(i32 %6, i32 2)
%8 = load i8, i8* %2
%9 = sext i8 %8 to i64
%10 = add nsw i64 %9, %7
%11 = trunc i64 %10 to i8
store i8 %11, i8* %2
%12 = load i8, i8* %2
%13 = sext i8 %12 to i32
switch i32 %13, label %17 [
i32 97, label %14
i32 98, label %15
i32 0, label %16
]
14: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %3
br label %18
15: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %18
16: ; preds = %1
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %18
17: ; preds = %1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %18
18: ; preds = %17, %16, %15, %14
store i32 0, i32* %4
br label %19
19: ; preds = %53, %18
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 5
br i1 %21, label %22, label %56
22: ; preds = %19
%23 = load i8, i8* %2
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 97
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = load i32, i32* %4
%28 = call i64 @somefunc1(i32 %27, i32 4)
%29 = load i8, i8* %2
%30 = sext i8 %29 to i64
%31 = add nsw i64 %30, %28
%32 = trunc i64 %31 to i8
store i8 %32, i8* %2
br label %52
33: ; preds = %22
%34 = load i8, i8* %2
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 98
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = load i32, i32* %4
%39 = call i64 @somefunc1(i32 %38, i32 5)
%40 = load i8, i8* %2
%41 = sext i8 %40 to i64
%42 = add nsw i64 %41, %39
%43 = trunc i64 %42 to i8
store i8 %43, i8* %2
br label %51
44: ; preds = %33
%45 = load i32, i32* %4
%46 = call i64 @somefunc1(i32 %45, i32 6)
%47 = load i8, i8* %2
%48 = sext i8 %47 to i64
%49 = add nsw i64 %48, %46
%50 = trunc i64 %49 to i8
store i8 %50, i8* %2
br label %51
51: ; preds = %44, %37
br label %52
52: ; preds = %51, %26
br label %53
53: ; preds = %52
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %19
56: ; preds = %19
%57 = load i8, i8* %2
%58 = load i8*, i8** %3
%59 = getelementptr inbounds i8, i8* %58, i64 0
store i8 %57, i8* %59
%60 = load i8*, i8** %3
ret i8* %60
}

LLVM IR (-O2):
@.str = [6 x i8] c"Got a\00"
@.str.1 = [6 x i8] c"Got b\00"
@.str.2 = [13 x i8] c"For serious?\00"
@.str.3 = [16 x i8] c"Unknown command\00"
define i8* @dothings(i8 signext %0) {
%2 = sext i8 %0 to i32
%3 = tail call i64 @somefunc1(i32 %2, i32 2)
%4 = trunc i64 %3 to i8
%5 = add i8 %4, %0
%6 = sext i8 %5 to i32
switch i32 %6, label %9 [
i32 97, label %10
i32 98, label %7
i32 0, label %8
]
7: ; preds = %1
br label %10
8: ; preds = %1
br label %10
9: ; preds = %1
br label %10
10: ; preds = %1, %9, %8, %7
%11 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), %9 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %1 ]
%12 = icmp eq i8 %5, 98
%13 = select i1 %12, i32 5, i32 6
%14 = icmp eq i8 %5, 97
%15 = select i1 %14, i32 4, i32 %13
%16 = tail call i64 @somefunc1(i32 0, i32 %15)
%17 = trunc i64 %16 to i8
%18 = add i8 %5, %17
%19 = icmp eq i8 %18, 98
%20 = select i1 %19, i32 5, i32 6
%21 = icmp eq i8 %18, 97
%22 = select i1 %21, i32 4, i32 %20
%23 = tail call i64 @somefunc1(i32 1, i32 %22)
%24 = trunc i64 %23 to i8
%25 = add i8 %18, %24
%26 = icmp eq i8 %25, 98
%27 = select i1 %26, i32 5, i32 6
%28 = icmp eq i8 %25, 97
%29 = select i1 %28, i32 4, i32 %27
%30 = tail call i64 @somefunc1(i32 2, i32 %29)
%31 = trunc i64 %30 to i8
%32 = add i8 %25, %31
%33 = icmp eq i8 %32, 98
%34 = select i1 %33, i32 5, i32 6
%35 = icmp eq i8 %32, 97
%36 = select i1 %35, i32 4, i32 %34
%37 = tail call i64 @somefunc1(i32 3, i32 %36)
%38 = trunc i64 %37 to i8
%39 = add i8 %32, %38
%40 = icmp eq i8 %39, 98
%41 = select i1 %40, i32 5, i32 6
%42 = icmp eq i8 %39, 97
%43 = select i1 %42, i32 4, i32 %41
%44 = tail call i64 @somefunc1(i32 4, i32 %43)
ret i8* %11
}