#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 get_triggers(size_t, char *, size_t);
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
scalar_t__ strlen(char *);
char *strstr(char *, char *);
char *strtok(char *, char *);
int get_trigger(size_t led_number, char *buf, size_t buf_len) {
  int err;
  char *active;
  if ((err = get_triggers(led_number, buf, buf_len)) < 0) {
    return err;
  }
  buf[buf_len - 1] = '\0';
  active = strstr(buf, "[") + 1;
  active = strtok(active, "[]");
  memmove(buf, active, strlen(active) + 1);
  return 1;
}


x86 assembly (clang, -O0):
<get_trigger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <get_triggers@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    118c <get_trigger+0x3c>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fc <get_trigger+0xac>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1070 <strstr@plt>
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1050 <memmove@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_trigger>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
call   1030 <get_triggers@plt>
test   %eax,%eax
js     11a5 <get_trigger+0x55>
movb   $0x0,-0x1(%rbx,%r14,1)
mov    %r14,%rdi
mov    $0x5b,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <memmove@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"[\00"
@.str.1 = [3 x i8] c"[]\00"
define i32 @get_trigger(i64 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
store i64 %0, i64* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i64, i64* %5
%11 = load i8*, i8** %6
%12 = load i64, i64* %7
%13 = call i32 @get_triggers(i64 %10, i8* %11, i64 %12)
store i32 %13, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %8
store i32 %16, i32* %4
br label %33
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = load i64, i64* %7
%20 = sub i64 %19, 1
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 0, i8* %21
%22 = load i8*, i8** %6
%23 = call i8* @strstr(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = call i8* @strtok(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %26, i8** %9
%27 = load i8*, i8** %6
%28 = load i8*, i8** %9
%29 = load i8*, i8** %9
%30 = call i64 @strlen(i8* %29)
%31 = add nsw i64 %30, 1
%32 = call i32 @memmove(i8* %27, i8* %28, i64 %31)
store i32 1, i32* %4
br label %33
33: ; preds = %17, %15
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"[]\00"
define i32 @get_trigger(i64 %0, i8* %1, i64 %2) {
%4 = tail call i32 @get_triggers(i64 %0, i8* %1, i64 %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = add i64 %2, -1
%8 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 0, i8* %8
%9 = tail call i8* @strchr(i8* dereferenceable(1) %1, i32 91)
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = tail call i8* @strtok(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%13 = add nsw i64 %12, 1
%14 = tail call i32 @memmove(i8* %1, i8* %11, i64 %13)
br label %15
15: ; preds = %3, %6
%16 = phi i32 [ 1, %6 ], [ %4, %3 ]
ret i32 %16
}