#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 t_weelist_item {
  int dummy;
};
struct t_weelist {
  int dummy;
};
struct t_gui_buffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gui_buffer_set_highlight_words(struct t_gui_buffer *,
                                                  char *);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char const *);
struct t_weelist_item *weelist_get(struct t_weelist *, int /*<<< orphan*/);
struct t_weelist_item *weelist_next(struct t_weelist_item *);
char *weelist_string(struct t_weelist_item *);
void gui_buffer_set_highlight_words_list(struct t_gui_buffer *buffer,
                                         struct t_weelist *list) {
  struct t_weelist_item *ptr_list_item;
  int length;
  const char *ptr_string;
  char *words;
  if (!buffer)
    return;
  length = 0;
  for (ptr_list_item = weelist_get(list, 0); ptr_list_item;
       ptr_list_item = weelist_next(ptr_list_item)) {
    ptr_string = weelist_string(ptr_list_item);
    if (ptr_string)
      length += strlen(ptr_string) + 1;
  }
  length += 2;
  words = malloc(length);
  if (!words)
    return;
  words[0] = '\0';
  for (ptr_list_item = weelist_get(list, 0); ptr_list_item;
       ptr_list_item = weelist_next(ptr_list_item)) {
    ptr_string = weelist_string(ptr_list_item);
    if (ptr_string) {
      strcat(words, ptr_string);
      if (weelist_next(ptr_list_item))
        strcat(words, ",");
    }
  }
  gui_buffer_set_highlight_words(buffer, words);
  free(words);
}


x86 assembly (clang, -O0):
<gui_buffer_set_highlight_words_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a0 <gui_buffer_set_highlight_words_list+0x20>
jmp    12ca <gui_buffer_set_highlight_words_list+0x14a>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1060 <weelist_get@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     120a <gui_buffer_set_highlight_words_list+0x8a>
mov    -0x18(%rbp),%rdi
call   1040 <weelist_string@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11f3 <gui_buffer_set_highlight_words_list+0x73>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
jmp    11f8 <gui_buffer_set_highlight_words_list+0x78>
mov    -0x18(%rbp),%rdi
call   10a0 <weelist_next@plt>
mov    %rax,-0x18(%rbp)
jmp    11b6 <gui_buffer_set_highlight_words_list+0x36>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    122f <gui_buffer_set_highlight_words_list+0xaf>
jmp    12ca <gui_buffer_set_highlight_words_list+0x14a>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1060 <weelist_get@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12b4 <gui_buffer_set_highlight_words_list+0x134>
mov    -0x18(%rbp),%rdi
call   1040 <weelist_string@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     129d <gui_buffer_set_highlight_words_list+0x11d>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <weelist_next@plt>
cmp    $0x0,%rax
je     1298 <gui_buffer_set_highlight_words_list+0x118>
mov    -0x30(%rbp),%rdi
lea    0xd6d(%rip),%rsi
call   1090 <strcat@plt>
jmp    129d <gui_buffer_set_highlight_words_list+0x11d>
jmp    12a2 <gui_buffer_set_highlight_words_list+0x122>
mov    -0x18(%rbp),%rdi
call   10a0 <weelist_next@plt>
mov    %rax,-0x18(%rbp)
jmp    1245 <gui_buffer_set_highlight_words_list+0xc5>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <gui_buffer_set_highlight_words@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_buffer_set_highlight_words_list>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1262 <gui_buffer_set_highlight_words_list+0xe2>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %r12d,%r12d
mov    %rsi,%rdi
xor    %esi,%esi
call   1060 <weelist_get@plt>
test   %rax,%rax
je     11ee <gui_buffer_set_highlight_words_list+0x6e>
mov    %rax,%rbx
xor    %r12d,%r12d
jmp    11d0 <gui_buffer_set_highlight_words_list+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <weelist_next@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ee <gui_buffer_set_highlight_words_list+0x6e>
mov    %rbx,%rdi
call   1040 <weelist_string@plt>
test   %rax,%rax
je     11c0 <gui_buffer_set_highlight_words_list+0x40>
mov    %rax,%rdi
call   1050 <strlen@plt>
add    %eax,%r12d
add    $0x1,%r12d
jmp    11c0 <gui_buffer_set_highlight_words_list+0x40>
add    $0x2,%r12d
mov    %r12d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1262 <gui_buffer_set_highlight_words_list+0xe2>
mov    %rax,%r12
movb   $0x0,(%rax)
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <weelist_get@plt>
test   %rax,%rax
je     126e <gui_buffer_set_highlight_words_list+0xee>
mov    %rax,%rbx
lea    0xde2(%rip),%r15
jmp    1230 <gui_buffer_set_highlight_words_list+0xb0>
mov    %rbx,%rdi
call   10a0 <weelist_next@plt>
mov    %rax,%rbx
test   %rax,%rax
je     126e <gui_buffer_set_highlight_words_list+0xee>
mov    %rbx,%rdi
call   1040 <weelist_string@plt>
test   %rax,%rax
je     1220 <gui_buffer_set_highlight_words_list+0xa0>
mov    %r12,%rdi
mov    %rax,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   10a0 <weelist_next@plt>
test   %rax,%rax
je     1220 <gui_buffer_set_highlight_words_list+0xa0>
mov    %r12,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
jmp    1220 <gui_buffer_set_highlight_words_list+0xa0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <gui_buffer_set_highlight_words@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.t_gui_buffer = type { i32 }
%struct.t_weelist = type { i32 }
%struct.t_weelist_item = type { i32 }
@.str = [2 x i8] c",\00"
define void @gui_buffer_set_highlight_words_list(%struct.t_gui_buffer* %0, %struct.t_weelist* %1) {
%3 = alloca %struct.t_gui_buffer*
%4 = alloca %struct.t_weelist*
%5 = alloca %struct.t_weelist_item*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store %struct.t_gui_buffer* %0, %struct.t_gui_buffer** %3
store %struct.t_weelist* %1, %struct.t_weelist** %4
%9 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %3
%10 = icmp ne %struct.t_gui_buffer* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
br label %77
12: ; preds = %2
store i32 0, i32* %6
%13 = load %struct.t_weelist*, %struct.t_weelist** %4
%14 = call %struct.t_weelist_item* @weelist_get(%struct.t_weelist* %13, i32 0)
store %struct.t_weelist_item* %14, %struct.t_weelist_item** %5
br label %15
15: ; preds = %32, %12
%16 = load %struct.t_weelist_item*, %struct.t_weelist_item** %5
%17 = icmp ne %struct.t_weelist_item* %16, null
br i1 %17, label %18, label %35
18: ; preds = %15
%19 = load %struct.t_weelist_item*, %struct.t_weelist_item** %5
%20 = call i8* @weelist_string(%struct.t_weelist_item* %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = load i8*, i8** %7
%25 = call i64 @strlen(i8* %24)
%26 = add nsw i64 %25, 1
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %6
br label %31
31: ; preds = %23, %18
br label %32
32: ; preds = %31
%33 = load %struct.t_weelist_item*, %struct.t_weelist_item** %5
%34 = call %struct.t_weelist_item* @weelist_next(%struct.t_weelist_item* %33)
store %struct.t_weelist_item* %34, %struct.t_weelist_item** %5
br label %15
35: ; preds = %15
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 2
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = call i8* @malloc(i32 %38)
store i8* %39, i8** %8
%40 = load i8*, i8** %8
%41 = icmp ne i8* %40, null
br i1 %41, label %43, label %42
42: ; preds = %35
br label %77
43: ; preds = %35
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i64 0
store i8 0, i8* %45
%46 = load %struct.t_weelist*, %struct.t_weelist** %4
%47 = call %struct.t_weelist_item* @weelist_get(%struct.t_weelist* %46, i32 0)
store %struct.t_weelist_item* %47, %struct.t_weelist_item** %5
br label %48
48: ; preds = %68, %43
%49 = load %struct.t_weelist_item*, %struct.t_weelist_item** %5
%50 = icmp ne %struct.t_weelist_item* %49, null
br i1 %50, label %51, label %71
51: ; preds = %48
%52 = load %struct.t_weelist_item*, %struct.t_weelist_item** %5
%53 = call i8* @weelist_string(%struct.t_weelist_item* %52)
store i8* %53, i8** %7
%54 = load i8*, i8** %7
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %67
56: ; preds = %51
%57 = load i8*, i8** %8
%58 = load i8*, i8** %7
%59 = call i32 @strcat(i8* %57, i8* %58)
%60 = load %struct.t_weelist_item*, %struct.t_weelist_item** %5
%61 = call %struct.t_weelist_item* @weelist_next(%struct.t_weelist_item* %60)
%62 = icmp ne %struct.t_weelist_item* %61, null
br i1 %62, label %63, label %66
63: ; preds = %56
%64 = load i8*, i8** %8
%65 = call i32 @strcat(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %66
66: ; preds = %63, %56
br label %67
67: ; preds = %66, %51
br label %68
68: ; preds = %67
%69 = load %struct.t_weelist_item*, %struct.t_weelist_item** %5
%70 = call %struct.t_weelist_item* @weelist_next(%struct.t_weelist_item* %69)
store %struct.t_weelist_item* %70, %struct.t_weelist_item** %5
br label %48
71: ; preds = %48
%72 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %3
%73 = load i8*, i8** %8
%74 = call i32 @gui_buffer_set_highlight_words(%struct.t_gui_buffer* %72, i8* %73)
%75 = load i8*, i8** %8
%76 = call i32 @free(i8* %75)
br label %77
77: ; preds = %71, %42, %11
ret void
}

LLVM IR (-O2):
%struct.t_gui_buffer = type { i32 }
%struct.t_weelist = type { i32 }
%struct.t_weelist_item = type { i32 }
@.str = [2 x i8] c",\00"
define void @gui_buffer_set_highlight_words_list(%struct.t_gui_buffer* %0, %struct.t_weelist* %1) {
%3 = icmp eq %struct.t_gui_buffer* %0, null
br i1 %3, label %45, label %4
4: ; preds = %2
%5 = tail call %struct.t_weelist_item* @weelist_get(%struct.t_weelist* %1, i32 0)
%6 = icmp eq %struct.t_weelist_item* %5, null
br i1 %6, label %21, label %7
7: ; preds = %4, %17
%8 = phi %struct.t_weelist_item* [ %19, %17 ], [ %5, %4 ]
%9 = phi i32 [ %18, %17 ], [ 0, %4 ]
%10 = tail call i8* @weelist_string(%struct.t_weelist_item* %8)
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = tail call i64 @strlen(i8* %10)
%14 = trunc i64 %13 to i32
%15 = add i32 %9, 1
%16 = add i32 %15, %14
br label %17
17: ; preds = %7, %12
%18 = phi i32 [ %16, %12 ], [ %9, %7 ]
%19 = tail call %struct.t_weelist_item* @weelist_next(%struct.t_weelist_item* %8)
%20 = icmp eq %struct.t_weelist_item* %19, null
br i1 %20, label %21, label %7
21: ; preds = %17, %4
%22 = phi i32 [ 0, %4 ], [ %18, %17 ]
%23 = add nsw i32 %22, 2
%24 = tail call i8* @malloc(i32 %23)
%25 = icmp eq i8* %24, null
br i1 %25, label %45, label %26
26: ; preds = %21
store i8 0, i8* %24
%27 = tail call %struct.t_weelist_item* @weelist_get(%struct.t_weelist* %1, i32 0)
%28 = icmp eq %struct.t_weelist_item* %27, null
br i1 %28, label %42, label %29
29: ; preds = %26, %39
%30 = phi %struct.t_weelist_item* [ %40, %39 ], [ %27, %26 ]
%31 = tail call i8* @weelist_string(%struct.t_weelist_item* %30)
%32 = icmp eq i8* %31, null
br i1 %32, label %39, label %33
33: ; preds = %29
%34 = tail call i32 @strcat(i8* %24, i8* %31)
%35 = tail call %struct.t_weelist_item* @weelist_next(%struct.t_weelist_item* %30)
%36 = icmp eq %struct.t_weelist_item* %35, null
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = tail call i32 @strcat(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %39
39: ; preds = %29, %37, %33
%40 = tail call %struct.t_weelist_item* @weelist_next(%struct.t_weelist_item* %30)
%41 = icmp eq %struct.t_weelist_item* %40, null
br i1 %41, label %42, label %29
42: ; preds = %39, %26
%43 = tail call i32 @gui_buffer_set_highlight_words(%struct.t_gui_buffer* %0, i8* %24)
%44 = tail call i32 @free(i8* %24)
br label %45
45: ; preds = %21, %2, %42
ret void
}