#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__ index(char *, char);
int roll(int, int, int);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, ...);
int rolls(char *dstring) {
  int b = 1, q = 1, d = 8;
  if (index(dstring, 'b')) {
    sscanf(dstring, "%db%dd%d", &b, &q, &d);
  } else {
    sscanf(dstring, "%dd%d", &q, &d);
    b = q;
  }
  return roll(b, q, d);
}


x86 assembly (clang, -O0):
<rolls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x8,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x62,%esi
call   1030 <index@plt>
cmp    $0x0,%rax
je     118c <rolls+0x5c>
mov    -0x8(%rbp),%rdi
lea    0xe8c(%rip),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
mov    $0x0,%al
call   1040 <sscanf@plt>
jmp    11ac <rolls+0x7c>
mov    -0x8(%rbp),%rdi
lea    0xe6c(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1040 <sscanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <roll@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rolls>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x1,0xc(%rsp)
movl   $0x1,0x4(%rsp)
movl   $0x8,0x8(%rsp)
mov    $0x62,%esi
call   1030 <index@plt>
test   %rax,%rax
je     1189 <rolls+0x59>
lea    0xe9a(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
mov    0xc(%rsp),%edi
mov    0x4(%rsp),%esi
jmp    11ae <rolls+0x7e>
lea    0xe73(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <sscanf@plt>
mov    0x4(%rsp),%esi
mov    %esi,0xc(%rsp)
mov    %esi,%edi
mov    0x8(%rsp),%edx
call   1050 <roll@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%db%dd%d\00"
@.str.1 = [6 x i8] c"%dd%d\00"
define i32 @rolls(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 1, i32* %3
store i32 1, i32* %4
store i32 8, i32* %5
%6 = load i8*, i8** %2
%7 = call i64 @index(i8* %6, i8 signext 98)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
br label %16
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%15 = load i32, i32* %4
store i32 %15, i32* %3
br label %16
16: ; preds = %12, %9
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 @roll(i32 %17, i32 %18, i32 %19)
ret i32 %20
}

LLVM IR (-O2):
@.str = [9 x i8] c"%db%dd%d\00"
@.str.1 = [6 x i8] c"%dd%d\00"
define i32 @rolls(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%6 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%7 = bitcast i32* %4 to i8*
store i32 8, i32* %4
%8 = tail call i64 @index(i8* %0, i8 signext 98)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%12 = load i32, i32* %2
%13 = load i32, i32* %3
br label %17
14: ; preds = %1
%15 = call i32 (i8*, i8*, i32*, i32*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%16 = load i32, i32* %3
store i32 %16, i32* %2
br label %17
17: ; preds = %14, %10
%18 = phi i32 [ %16, %14 ], [ %13, %10 ]
%19 = phi i32 [ %16, %14 ], [ %12, %10 ]
%20 = load i32, i32* %4
%21 = call i32 @roll(i32 %19, i32 %18, i32 %20)
ret i32 %21
}