#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*/ arg_list_cpy;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *get_arg_from_call(char const *, size_t *);
char *get_stmt_end(char *, size_t);
scalar_t__ hefesto_mloc(size_t const);
char *infix2postfix(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t const);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
size_t strnlen(char *, int);
char *infix2postfix_args(const char *arg_list, const size_t arg_list_size) {
  char *e = NULL;
  const char *ap = NULL, *ap_end = NULL;
  char *arg_pf = NULL;
  size_t offset = 0;
  size_t real_arg_list_size = 0;
  char *retval = NULL;
  char arg_list_cpy[8192];
  if (arg_list == NULL) {
    return NULL;
  }
  memset(arg_list_cpy, 0, sizeof(arg_list_cpy));
  strncpy(arg_list_cpy, arg_list, sizeof(arg_list_cpy) - 1);
  real_arg_list_size = strnlen(arg_list_cpy, sizeof(arg_list_cpy));
  ap_end = get_stmt_end(arg_list_cpy, real_arg_list_size);
  ap = &arg_list_cpy[0];
  if (ap_end != NULL) {
    memset((char *)ap_end, 0, real_arg_list_size - (ap_end - ap));
  }
  while (*ap != '(' && *ap != 0) {
    ap++;
  }
  if (*ap == 0) {
    return NULL;
  }
  ap++;
  retval = (char *)hefesto_mloc(arg_list_size * 2);
  memset(retval, 0, arg_list_size * 2);
  *retval = '(';
  e = get_arg_from_call(ap, &offset);
  while (*e) {
    arg_pf = infix2postfix(e, strlen(e), 1);
    strcat(retval, arg_pf);
    free(arg_pf);
    free(e);
    if (arg_list_cpy[offset] == ',') {
      offset++;
    }
    e = get_arg_from_call(arg_list_cpy, &offset);
    if (*e) {
      strcat(retval, ",");
    } else {
      strcat(retval, ")");
    }
  }
  free(e);
  return retval;
}


x86 assembly (clang, -O0):
<infix2postfix_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2060,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1203 <infix2postfix_args+0x63>
movq   $0x0,-0x8(%rbp)
jmp    1414 <infix2postfix_args+0x274>
lea    -0x2050(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1080 <memset@plt>
lea    -0x2050(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1fff,%edx
call   1040 <strncpy@plt>
lea    -0x2050(%rbp),%rdi
mov    $0x2000,%esi
call   1090 <strnlen@plt>
mov    %rax,-0x48(%rbp)
lea    -0x2050(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1050 <get_stmt_end@plt>
mov    %rax,-0x30(%rbp)
lea    -0x2050(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1287 <infix2postfix_args+0xe7>
mov    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sub    %rax,%rdx
xor    %esi,%esi
call   1080 <memset@plt>
jmp    128c <infix2postfix_args+0xec>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x28,%ecx
mov    %al,-0x2051(%rbp)
je     12b7 <infix2postfix_args+0x117>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x2051(%rbp)
mov    -0x2051(%rbp),%al
test   $0x1,%al
jne    12ca <infix2postfix_args+0x12a>
jmp    12db <infix2postfix_args+0x13b>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    128c <infix2postfix_args+0xec>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12f8 <infix2postfix_args+0x158>
movq   $0x0,-0x8(%rbp)
jmp    1414 <infix2postfix_args+0x274>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0x1,%rdi
call   10a0 <hefesto_mloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
shl    $0x1,%rdx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x50(%rbp),%rax
movb   $0x28,(%rax)
mov    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <get_arg_from_call@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1403 <infix2postfix_args+0x263>
mov    -0x20(%rbp),%rax
mov    %rax,-0x2060(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x2060(%rbp),%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   10c0 <infix2postfix@plt>
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
movsbl -0x2050(%rbp,%rax,1),%eax
ff
cmp    $0x2c,%eax
jne    13b8 <infix2postfix_args+0x218>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
lea    -0x2050(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1070 <get_arg_from_call@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     13ee <infix2postfix_args+0x24e>
mov    -0x50(%rbp),%rdi
lea    0xc1c(%rip),%rsi
call   10b0 <strcat@plt>
jmp    13fe <infix2postfix_args+0x25e>
mov    -0x50(%rbp),%rdi
lea    0xc09(%rip),%rsi
call   10b0 <strcat@plt>
jmp    1340 <infix2postfix_args+0x1a0>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<infix2postfix_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
movq   $0x0,0x8(%rsp)
test   %rdi,%rdi
je     1242 <infix2postfix_args+0xa2>
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x10(%rsp),%r15
mov    $0x2000,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1fff,%edx
call   1040 <strncpy@plt>
mov    %r15,%rdi
mov    $0x2000,%esi
call   1090 <strnlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <get_stmt_end@plt>
test   %rax,%rax
je     1220 <infix2postfix_args+0x80>
add    %r15,%rbx
sub    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1080 <memset@plt>
lea    0x11(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl -0x1(%rbx),%eax
test   %al,%al
je     1242 <infix2postfix_args+0xa2>
cmp    $0x28,%al
je     124a <infix2postfix_args+0xaa>
add    $0x1,%rbx
jmp    1230 <infix2postfix_args+0x90>
xor    %r12d,%r12d
jmp    131b <infix2postfix_args+0x17b>
add    %r14,%r14
mov    %r14,%rdi
call   10a0 <hefesto_mloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1080 <memset@plt>
movb   $0x28,(%r12)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <get_arg_from_call@plt>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     1313 <infix2postfix_args+0x173>
lea    0x8(%rsp),%r15
lea    0xd73(%rip),%rbp
lea    0xd6a(%rip),%r14
jmp    12c7 <infix2postfix_args+0x127>
nopl   0x0(%rax,%rax,1)
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
call   1070 <get_arg_from_call@plt>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
mov    %r14,%rsi
cmove  %rbp,%rsi
mov    %r12,%rdi
call   10b0 <strcat@plt>
cmpb   $0x0,(%rbx)
je     1313 <infix2postfix_args+0x173>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   10c0 <infix2postfix@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    %rax,%rsi
call   10b0 <strcat@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rax
cmpb   $0x2c,0x10(%rsp,%rax,1)
jne    12a0 <infix2postfix_args+0x100>
add    $0x1,%rax
mov    %rax,0x8(%rsp)
jmp    12a0 <infix2postfix_args+0x100>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [2 x i8] c")\00"
define i8* @infix2postfix_args(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca [8192 x i8]
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i64 0, i64* %10
store i64 0, i64* %11
store i8* null, i8** %12
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i8* null, i8** %3
br label %118
17: ; preds = %2
%18 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i64 8192)
%20 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 0
%21 = load i8*, i8** %4
%22 = call i32 @strncpy(i8* %20, i8* %21, i32 8191)
%23 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 0
%24 = call i64 @strnlen(i8* %23, i32 8192)
store i64 %24, i64* %11
%25 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 0
%26 = load i64, i64* %11
%27 = call i8* @get_stmt_end(i8* %25, i64 %26)
store i8* %27, i8** %8
%28 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 0
store i8* %28, i8** %7
%29 = load i8*, i8** %8
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %41
31: ; preds = %17
%32 = load i8*, i8** %8
%33 = load i64, i64* %11
%34 = load i8*, i8** %8
%35 = load i8*, i8** %7
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = sub i64 %33, %38
%40 = call i32 @memset(i8* %32, i32 0, i64 %39)
br label %41
41: ; preds = %31, %17
br label %42
42: ; preds = %54, %41
%43 = load i8*, i8** %7
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 40
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i8*, i8** %7
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 0
br label %52
52: ; preds = %47, %42
%53 = phi i1 [ false, %42 ], [ %51, %47 ]
br i1 %53, label %54, label %57
54: ; preds = %52
%55 = load i8*, i8** %7
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %7
br label %42
57: ; preds = %52
%58 = load i8*, i8** %7
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %57
store i8* null, i8** %3
br label %118
63: ; preds = %57
%64 = load i8*, i8** %7
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %7
%66 = load i64, i64* %5
%67 = mul i64 %66, 2
%68 = call i64 @hefesto_mloc(i64 %67)
%69 = inttoptr i64 %68 to i8*
store i8* %69, i8** %12
%70 = load i8*, i8** %12
%71 = load i64, i64* %5
%72 = mul i64 %71, 2
%73 = call i32 @memset(i8* %70, i32 0, i64 %72)
%74 = load i8*, i8** %12
store i8 40, i8* %74
%75 = load i8*, i8** %7
%76 = call i8* @get_arg_from_call(i8* %75, i64* %10)
store i8* %76, i8** %6
br label %77
77: ; preds = %113, %63
%78 = load i8*, i8** %6
%79 = load i8, i8* %78
%80 = icmp ne i8 %79, 0
br i1 %80, label %81, label %114
81: ; preds = %77
%82 = load i8*, i8** %6
%83 = load i8*, i8** %6
%84 = call i32 @strlen(i8* %83)
%85 = call i8* @infix2postfix(i8* %82, i32 %84, i32 1)
store i8* %85, i8** %9
%86 = load i8*, i8** %12
%87 = load i8*, i8** %9
%88 = call i32 @strcat(i8* %86, i8* %87)
%89 = load i8*, i8** %9
%90 = call i32 @free(i8* %89)
%91 = load i8*, i8** %6
%92 = call i32 @free(i8* %91)
%93 = load i64, i64* %10
%94 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 %93
%95 = load i8, i8* %94
%96 = sext i8 %95 to i32
%97 = icmp eq i32 %96, 44
br i1 %97, label %98, label %101
98: ; preds = %81
%99 = load i64, i64* %10
%100 = add i64 %99, 1
store i64 %100, i64* %10
br label %101
101: ; preds = %98, %81
%102 = getelementptr inbounds [8192 x i8], [8192 x i8]* %13, i64 0, i64 0
%103 = call i8* @get_arg_from_call(i8* %102, i64* %10)
store i8* %103, i8** %6
%104 = load i8*, i8** %6
%105 = load i8, i8* %104
%106 = icmp ne i8 %105, 0
br i1 %106, label %107, label %110
107: ; preds = %101
%108 = load i8*, i8** %12
%109 = call i32 @strcat(i8* %108, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %113
110: ; preds = %101
%111 = load i8*, i8** %12
%112 = call i32 @strcat(i8* %111, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %113
113: ; preds = %110, %107
br label %77
114: ; preds = %77
%115 = load i8*, i8** %6
%116 = call i32 @free(i8* %115)
%117 = load i8*, i8** %12
store i8* %117, i8** %3
br label %118
118: ; preds = %114, %62, %16
%119 = load i8*, i8** %3
ret i8* %119
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [2 x i8] c")\00"
define i8* @infix2postfix_args(i8* %0, i64 %1) {
%3 = alloca i64
%4 = alloca [8192 x i8]
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%7 = icmp eq i8* %0, null
br i1 %7, label %59, label %8
8: ; preds = %2
%9 = call i32 @memset(i8* %6, i32 0, i64 8192)
%10 = call i32 @strncpy(i8* %6, i8* %0, i32 8191)
%11 = call i64 @strnlen(i8* %6, i32 8192)
%12 = call i8* @get_stmt_end(i8* %6, i64 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %8
%15 = ptrtoint i8* %12 to i64
%16 = ptrtoint [8192 x i8]* %4 to i64
%17 = add i64 %11, %16
%18 = sub i64 %17, %15
%19 = call i32 @memset(i8* %12, i32 0, i64 %18)
br label %20
20: ; preds = %14, %8
br label %21
21: ; preds = %20, %24
%22 = phi i8* [ %25, %24 ], [ %6, %20 ]
%23 = load i8, i8* %22
switch i8 %23, label %24 [
i8 0, label %59
i8 40, label %26
]
24: ; preds = %21
%25 = getelementptr inbounds i8, i8* %22, i64 1
br label %21
26: ; preds = %21
%27 = getelementptr inbounds i8, i8* %22, i64 1
%28 = shl i64 %1, 1
%29 = call i64 @hefesto_mloc(i64 %28)
%30 = inttoptr i64 %29 to i8*
%31 = call i32 @memset(i8* %30, i32 0, i64 %28)
store i8 40, i8* %30
%32 = call i8* @get_arg_from_call(i8* %27, i64* %3)
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %56, label %35
35: ; preds = %26, %48
%36 = phi i8* [ %49, %48 ], [ %32, %26 ]
%37 = call i32 @strlen(i8* %36)
%38 = call i8* @infix2postfix(i8* %36, i32 %37, i32 1)
%39 = call i32 @strcat(i8* %30, i8* %38)
%40 = call i32 @free(i8* %38)
%41 = call i32 @free(i8* %36)
%42 = load i64, i64* %3
%43 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 44
br i1 %45, label %46, label %48
46: ; preds = %35
%47 = add i64 %42, 1
store i64 %47, i64* %3
br label %48
48: ; preds = %46, %35
%49 = call i8* @get_arg_from_call(i8* %6, i64* %3)
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 0
%52 = select i1 %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%53 = call i32 @strcat(i8* %30, i8* %52)
%54 = load i8, i8* %49
%55 = icmp eq i8 %54, 0
br i1 %55, label %56, label %35
56: ; preds = %48, %26
%57 = phi i8* [ %32, %26 ], [ %49, %48 ]
%58 = call i32 @free(i8* %57)
br label %59
59: ; preds = %21, %2, %56
%60 = phi i8* [ %30, %56 ], [ null, %2 ], [ null, %21 ]
ret i8* %60
}