#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*/ isdigit(char const);
int /*<<< orphan*/ strchr(char const *, char);
char get_str_command(const char *str) {
  switch (str[0]) {
  case '+':
    if (strchr(str, '%')) {
      return 'i';
    } else {
      return '+';
    }
  case '-':
    if (strchr(str, '%')) {
      return 'd';
    } else {
      return '-';
    }
  default:
    if (isdigit(str[0])) {
      if (strchr(str, '%')) {
        return 's';
      } else {
        return '.';
      }
    } else
      return 0;
  }
}


x86 assembly (clang, -O0):
<get_str_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x2b,%eax
je     1155 <get_str_command+0x35>
jmp    1144 <get_str_command+0x24>
mov    -0x14(%rbp),%eax
sub    $0x2d,%eax
je     117e <get_str_command+0x5e>
jmp    11a7 <get_str_command+0x87>
mov    -0x10(%rbp),%rdi
mov    $0x25,%esi
call   1040 <strchr@plt>
cmp    $0x0,%eax
je     1175 <get_str_command+0x55>
movb   $0x69,-0x1(%rbp)
jmp    11e9 <get_str_command+0xc9>
movb   $0x2b,-0x1(%rbp)
jmp    11e9 <get_str_command+0xc9>
mov    -0x10(%rbp),%rdi
mov    $0x25,%esi
call   1040 <strchr@plt>
cmp    $0x0,%eax
je     119e <get_str_command+0x7e>
movb   $0x64,-0x1(%rbp)
jmp    11e9 <get_str_command+0xc9>
movb   $0x2d,-0x1(%rbp)
jmp    11e9 <get_str_command+0xc9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     11e5 <get_str_command+0xc5>
mov    -0x10(%rbp),%rdi
mov    $0x25,%esi
call   1040 <strchr@plt>
cmp    $0x0,%eax
je     11dc <get_str_command+0xbc>
movb   $0x73,-0x1(%rbp)
jmp    11e9 <get_str_command+0xc9>
movb   $0x2e,-0x1(%rbp)
jmp    11e9 <get_str_command+0xc9>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_str_command>:
push   %rbx
mov    %rdi,%rbx
movsbl (%rdi),%edi
cmp    $0x2d,%edi
je     114c <get_str_command+0x2c>
cmp    $0x2b,%edi
jne    1167 <get_str_command+0x47>
mov    %rbx,%rdi
mov    $0x25,%esi
call   1040 <strchr@plt>
test   %eax,%eax
mov    $0x2b,%ecx
mov    $0x69,%eax
jmp    1189 <get_str_command+0x69>
mov    %rbx,%rdi
mov    $0x25,%esi
call   1040 <strchr@plt>
test   %eax,%eax
mov    $0x2d,%ecx
mov    $0x64,%eax
jmp    1189 <get_str_command+0x69>
call   1030 <isdigit@plt>
test   %eax,%eax
je     118e <get_str_command+0x6e>
mov    %rbx,%rdi
mov    $0x25,%esi
call   1040 <strchr@plt>
test   %eax,%eax
mov    $0x2e,%ecx
mov    $0x73,%eax
cmove  %ecx,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define signext i8 @get_str_command(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %20 [
i32 43, label %8
i32 45, label %14
]
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @strchr(i8* %9, i8 signext 37)
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
store i8 105, i8* %2
br label %33
13: ; preds = %8
store i8 43, i8* %2
br label %33
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = call i32 @strchr(i8* %15, i8 signext 37)
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i8 100, i8* %2
br label %33
19: ; preds = %14
store i8 45, i8* %2
br label %33
20: ; preds = %1
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = call i32 @isdigit(i8 signext %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i8*, i8** %3
%28 = call i32 @strchr(i8* %27, i8 signext 37)
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i8 115, i8* %2
br label %33
31: ; preds = %26
store i8 46, i8* %2
br label %33
32: ; preds = %20
store i8 0, i8* %2
br label %33
33: ; preds = %32, %31, %30, %19, %18, %13, %12
%34 = load i8, i8* %2
ret i8 %34
}

LLVM IR (-O2):
define signext i8 @get_str_command(i8* %0) {
%2 = load i8, i8* %0
%3 = sext i8 %2 to i32
switch i32 %3, label %12 [
i32 43, label %4
i32 45, label %8
]
4: ; preds = %1
%5 = tail call i32 @strchr(i8* %0, i8 signext 37)
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i8 43, i8 105
br label %19
8: ; preds = %1
%9 = tail call i32 @strchr(i8* %0, i8 signext 37)
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i8 45, i8 100
br label %19
12: ; preds = %1
%13 = tail call i32 @isdigit(i8 signext %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12
%16 = tail call i32 @strchr(i8* %0, i8 signext 37)
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i8 46, i8 115
br label %19
19: ; preds = %12, %15, %8, %4
%20 = phi i8 [ %7, %4 ], [ %11, %8 ], [ %18, %15 ], [ 0, %12 ]
ret i8 %20
}