#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 */
typedef int /*<<< orphan*/ funcname;

/* Variables and functions */
char *find_next_token(char const **, unsigned int *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
int strlen(char *);
char *variable_buffer_output(char *, char const *, int);
char *func_addsuffix_addprefix(char *o, char **argv, const char *funcname) {
  int fixlen = strlen(argv[0]);
  const char *list_iterator = argv[1];
  int is_addprefix =
      ((funcname) == ("addprefix") ||
       (*(funcname) == *("addprefix") &&
        (*(funcname) == '\0' || !strcmp((funcname) + 1, ("addprefix") + 1))));
  int is_addsuffix = !is_addprefix;
  int doneany = 0;
  const char *p;
  unsigned int len;
  while ((p = find_next_token(&list_iterator, &len)) != 0) {
    if (is_addprefix)
      o = variable_buffer_output(o, argv[0], fixlen);
    o = variable_buffer_output(o, p, len);
    if (is_addsuffix)
      o = variable_buffer_output(o, argv[0], fixlen);
    o = variable_buffer_output(o, " ", 1);
    doneany = 1;
  }
  if (doneany)
    --o;
  return o;
}


x86 assembly (clang, -O0):
<func_addsuffix_addprefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    $0x1,%al
lea    0xe88(%rip),%rcx
cmp    %rcx,-0x18(%rbp)
mov    %al,-0x45(%rbp)
je     11e2 <func_addsuffix_addprefix+0xa2>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
movsbl 0xe6d(%rip),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x46(%rbp)
jne    11dc <func_addsuffix_addprefix+0x9c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x47(%rbp)
je     11d6 <func_addsuffix_addprefix+0x96>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %eax,%edi
lea    0xe3b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x47(%rbp)
mov    -0x47(%rbp),%al
mov    %al,-0x46(%rbp)
mov    -0x46(%rbp),%al
mov    %al,-0x45(%rbp)
mov    -0x45(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x28(%rbp),%rdi
lea    -0x44(%rbp),%rsi
call   1060 <find_next_token@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     129b <func_addsuffix_addprefix+0x15b>
cmpl   $0x0,-0x2c(%rbp)
je     1241 <func_addsuffix_addprefix+0x101>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <variable_buffer_output@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1050 <variable_buffer_output@plt>
mov    %rax,-0x8(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     1276 <func_addsuffix_addprefix+0x136>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <variable_buffer_output@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd89(%rip),%rsi
mov    $0x1,%edx
call   1050 <variable_buffer_output@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1205 <func_addsuffix_addprefix+0xc5>
cmpl   $0x0,-0x34(%rbp)
je     12b1 <func_addsuffix_addprefix+0x171>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func_addsuffix_addprefix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    (%rsi),%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    0x8(%rbx),%rax
mov    %rax,0x10(%rsp)
lea    0xe8e(%rip),%rax
cmp    %rax,%r15
je     1198 <func_addsuffix_addprefix+0x58>
cmpb   $0x61,(%r15)
jne    119d <func_addsuffix_addprefix+0x5d>
add    $0x1,%r15d
lea    0xe79(%rip),%rsi
mov    %r15d,%edi
call   1040 <strcmp@plt>
test   %eax,%eax
sete   %r12b
jmp    11a0 <func_addsuffix_addprefix+0x60>
mov    $0x1,%r12b
jmp    11a0 <func_addsuffix_addprefix+0x60>
xor    %r12d,%r12d
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1060 <find_next_token@plt>
test   %rax,%rax
je     1231 <func_addsuffix_addprefix+0xf1>
mov    %rax,%r15
lea    0xc(%rsp),%r13
jmp    1209 <func_addsuffix_addprefix+0xc9>
xchg   %ax,%ax
mov    0xc(%rsp),%edx
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <variable_buffer_output@plt>
mov    (%rbx),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   1050 <variable_buffer_output@plt>
mov    %rax,%rdi
lea    0xe23(%rip),%rsi
mov    $0x1,%edx
call   1050 <variable_buffer_output@plt>
mov    %rax,%rbp
lea    0x10(%rsp),%rdi
mov    %r13,%rsi
call   1060 <find_next_token@plt>
mov    %rax,%r15
test   %rax,%rax
je     1228 <func_addsuffix_addprefix+0xe8>
test   %r12b,%r12b
je     11c0 <func_addsuffix_addprefix+0x80>
mov    (%rbx),%rsi
mov    %rbp,%rdi
mov    %r14d,%edx
call   1050 <variable_buffer_output@plt>
mov    0xc(%rsp),%edx
mov    %rax,%rdi
mov    %r15,%rsi
jmp    11d8 <func_addsuffix_addprefix+0x98>
mov    $0xffffffffffffffff,%rax
jmp    1233 <func_addsuffix_addprefix+0xf3>
xor    %eax,%eax
add    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"addprefix\00"
@.str.1 = [2 x i8] c" \00"
define i8* @func_addsuffix_addprefix(i8* %0, i8** %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %7
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %8
%21 = load i8*, i8** %6
%22 = icmp eq i8* %21, getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0)
br i1 %22, label %46, label %23
23: ; preds = %3
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = load i8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0)
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %26, %28
br i1 %29, label %30, label %44
30: ; preds = %23
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
br i1 %34, label %42, label %35
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = ptrtoint i8* %37 to i32
%39 = call i32 @strcmp(i32 %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 1))
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
br label %42
42: ; preds = %35, %30
%43 = phi i1 [ true, %30 ], [ %41, %35 ]
br label %44
44: ; preds = %42, %23
%45 = phi i1 [ false, %23 ], [ %43, %42 ]
br label %46
46: ; preds = %44, %3
%47 = phi i1 [ true, %3 ], [ %45, %44 ]
%48 = zext i1 %47 to i32
store i32 %48, i32* %9
%49 = load i32, i32* %9
%50 = icmp ne i32 %49, 0
%51 = xor i1 %50, true
%52 = zext i1 %51 to i32
store i32 %52, i32* %10
store i32 0, i32* %11
br label %53
53: ; preds = %80, %46
%54 = call i8* @find_next_token(i8** %8, i32* %13)
store i8* %54, i8** %12
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %83
56: ; preds = %53
%57 = load i32, i32* %9
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %66
59: ; preds = %56
%60 = load i8*, i8** %4
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 0
%63 = load i8*, i8** %62
%64 = load i32, i32* %7
%65 = call i8* @variable_buffer_output(i8* %60, i8* %63, i32 %64)
store i8* %65, i8** %4
br label %66
66: ; preds = %59, %56
%67 = load i8*, i8** %4
%68 = load i8*, i8** %12
%69 = load i32, i32* %13
%70 = call i8* @variable_buffer_output(i8* %67, i8* %68, i32 %69)
store i8* %70, i8** %4
%71 = load i32, i32* %10
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %80
73: ; preds = %66
%74 = load i8*, i8** %4
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 0
%77 = load i8*, i8** %76
%78 = load i32, i32* %7
%79 = call i8* @variable_buffer_output(i8* %74, i8* %77, i32 %78)
store i8* %79, i8** %4
br label %80
80: ; preds = %73, %66
%81 = load i8*, i8** %4
%82 = call i8* @variable_buffer_output(i8* %81, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i8* %82, i8** %4
store i32 1, i32* %11
br label %53
83: ; preds = %53
%84 = load i32, i32* %11
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i8*, i8** %4
%88 = getelementptr inbounds i8, i8* %87, i32 -1
store i8* %88, i8** %4
br label %89
89: ; preds = %86, %83
%90 = load i8*, i8** %4
ret i8* %90
}

LLVM IR (-O2):
@.str = [10 x i8] c"addprefix\00"
@.str.1 = [2 x i8] c" \00"
define i8* @func_addsuffix_addprefix(i8* %0, i8** nocapture %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = load i8*, i8** %1
%7 = tail call i32 @strlen(i8* %6)
%8 = bitcast i8** %4 to i8*
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
store i8* %10, i8** %4
%11 = icmp eq i8* %2, getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0)
br i1 %11, label %21, label %12
12: ; preds = %3
%13 = load i8, i8* %2
%14 = icmp eq i8 %13, 97
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %2, i64 1
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i32
%19 = tail call i32 @strcmp(i32 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 1))
%20 = icmp eq i32 %19, 0
br label %21
21: ; preds = %12, %15, %3
%22 = phi i1 [ true, %3 ], [ false, %12 ], [ %20, %15 ]
%23 = bitcast i32* %5 to i8*
%24 = call i8* @find_next_token(i8** %4, i32* %5)
%25 = icmp eq i8* %24, null
br i1 %25, label %44, label %26
26: ; preds = %21, %39
%27 = phi i8* [ %42, %39 ], [ %24, %21 ]
%28 = phi i8* [ %41, %39 ], [ %0, %21 ]
br i1 %22, label %29, label %34
29: ; preds = %26
%30 = load i8*, i8** %1
%31 = call i8* @variable_buffer_output(i8* %28, i8* %30, i32 %7)
%32 = load i32, i32* %5
%33 = call i8* @variable_buffer_output(i8* %31, i8* %27, i32 %32)
br label %39
34: ; preds = %26
%35 = load i32, i32* %5
%36 = call i8* @variable_buffer_output(i8* %28, i8* %27, i32 %35)
%37 = load i8*, i8** %1
%38 = call i8* @variable_buffer_output(i8* %36, i8* %37, i32 %7)
br label %39
39: ; preds = %29, %34
%40 = phi i8* [ %38, %34 ], [ %33, %29 ]
%41 = call i8* @variable_buffer_output(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%42 = call i8* @find_next_token(i8** %4, i32* %5)
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %26
44: ; preds = %39, %21
%45 = phi i64 [ 0, %21 ], [ -1, %39 ]
%46 = phi i8* [ %0, %21 ], [ %41, %39 ]
%47 = getelementptr i8, i8* %46, i64 %45
ret i8* %47
}