#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 */
struct mixer_ctl {
  int dummy;
};
struct mixer {
  int dummy;
};

/* Variables and functions */
int atoi(char *);
scalar_t__ isdigit(char);
struct mixer_ctl *mixer_get_control(struct mixer *, char *, unsigned int);
struct mixer_ctl *mixer_get_nth_control(struct mixer *, int);
char *strrchr(char *, char);
struct mixer_ctl *get_ctl(struct mixer *mixer, char *name) {
  char *p;
  unsigned idx = 0;
  if (isdigit(name[0]))
    return mixer_get_nth_control(mixer, atoi(name) - 1);
  p = strrchr(name, '#');
  if (p) {
    *p++ = 0;
    idx = atoi(p);
  }
  return mixer_get_control(mixer, name, idx);
}


x86 assembly (clang, -O0):
<get_ctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11a5 <get_ctl+0x55>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
sub    $0x1,%esi
call   1050 <mixer_get_nth_control@plt>
mov    %rax,-0x8(%rbp)
jmp    11f4 <get_ctl+0xa4>
mov    -0x18(%rbp),%rdi
mov    $0x23,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e0 <get_ctl+0x90>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1070 <mixer_get_control@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ctl>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movsbl (%rsi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1181 <get_ctl+0x31>
mov    %rbx,%rdi
call   1060 <atoi@plt>
lea    -0x1(%rax),%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <mixer_get_nth_control@plt>
mov    %rbx,%rdi
mov    $0x23,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11a6 <get_ctl+0x56>
mov    %rax,%rdi
add    $0x1,%rdi
movb   $0x0,(%rax)
call   1060 <atoi@plt>
mov    %eax,%edx
jmp    11a8 <get_ctl+0x58>
xor    %edx,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <mixer_get_control@plt>

LLVM IR (-O0):
%struct.mixer_ctl = type { i32 }
%struct.mixer = type { i32 }
define %struct.mixer_ctl* @get_ctl(%struct.mixer* %0, i8* %1) {
%3 = alloca %struct.mixer_ctl*
%4 = alloca %struct.mixer*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store %struct.mixer* %0, %struct.mixer** %4
store i8* %1, i8** %5
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = call i64 @isdigit(i8 signext %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load %struct.mixer*, %struct.mixer** %4
%15 = load i8*, i8** %5
%16 = call i32 @atoi(i8* %15)
%17 = sub nsw i32 %16, 1
%18 = call %struct.mixer_ctl* @mixer_get_nth_control(%struct.mixer* %14, i32 %17)
store %struct.mixer_ctl* %18, %struct.mixer_ctl** %3
br label %34
19: ; preds = %2
%20 = load i8*, i8** %5
%21 = call i8* @strrchr(i8* %20, i8 signext 35)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %6
store i8 0, i8* %25
%27 = load i8*, i8** %6
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %7
br label %29
29: ; preds = %24, %19
%30 = load %struct.mixer*, %struct.mixer** %4
%31 = load i8*, i8** %5
%32 = load i32, i32* %7
%33 = call %struct.mixer_ctl* @mixer_get_control(%struct.mixer* %30, i8* %31, i32 %32)
store %struct.mixer_ctl* %33, %struct.mixer_ctl** %3
br label %34
34: ; preds = %29, %13
%35 = load %struct.mixer_ctl*, %struct.mixer_ctl** %3
ret %struct.mixer_ctl* %35
}

LLVM IR (-O2):
%struct.mixer_ctl = type { i32 }
%struct.mixer = type { i32 }
define %struct.mixer_ctl* @get_ctl(%struct.mixer* %0, i8* %1) {
%3 = load i8, i8* %1
%4 = tail call i64 @isdigit(i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @atoi(i8* %1)
%8 = add nsw i32 %7, -1
%9 = tail call %struct.mixer_ctl* @mixer_get_nth_control(%struct.mixer* %0, i32 %8)
br label %19
10: ; preds = %2
%11 = tail call i8* @strrchr(i8* %1, i8 signext 35)
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %11, i64 1
store i8 0, i8* %11
%15 = tail call i32 @atoi(i8* %14)
br label %16
16: ; preds = %13, %10
%17 = phi i32 [ %15, %13 ], [ 0, %10 ]
%18 = tail call %struct.mixer_ctl* @mixer_get_control(%struct.mixer* %0, i8* %1, i32 %17)
br label %19
19: ; preds = %16, %6
%20 = phi %struct.mixer_ctl* [ %9, %6 ], [ %18, %16 ]
ret %struct.mixer_ctl* %20
}