#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 /*<<< orphan*/ assert(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ showstack();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strstr(char *, char *);
void process_function_args(char startstring[], int *arglength) {
  char endstring[64];
  char *argstring = (char *)malloc(strlen(startstring));
  char *saveptr = argstring;
  int i, printargs = 0;
  assert(startstring);
  *arglength = 0;
  strcpy(endstring, startstring);
  while ((*arglength < strlen(startstring)) && (endstring[*arglength] != ')'))
    (*arglength)++;
  if (endstring[*arglength] != ')') {
    fprintf(stderr, "Malformed function arguments %s\n", argstring);
    exit(-1);
  }
  printargs = *arglength;
  if (strstr(endstring, ". . .")) {
    printf("a variadic function ");
    printargs -= 7;
  } else
    printf("a function ");
  if (printargs) {
    printf("that takes ");
    for (i = 0; i < printargs; i++) {
      if (endstring[i] == ',')
        printf(" and");
      else
        putchar(endstring[i]);
    }
    printf(" args and ");
  }
  printf("that returns ");
  free(saveptr);
  return;
  showstack();
  printf("\nMismatched function arg delimiters.\n");
  if (argstring)
    free(saveptr);
  exit(-1);
}


x86 assembly (clang, -O0):
<process_function_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x70(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x69(%rbp)
jge    122c <process_function_args+0x8c>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x29,%eax
setne  %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    123c <process_function_args+0x9c>
jmp    124c <process_function_args+0xac>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11f3 <process_function_args+0x53>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x29,%eax
je     1284 <process_function_args+0xe4>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
lea    0xd8b(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xd89(%rip),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     12c1 <process_function_args+0x121>
lea    0xd79(%rip),%rdi
call   1070 <printf@plt>
mov    -0x68(%rbp),%eax
sub    $0x7,%eax
mov    %eax,-0x68(%rbp)
jmp    12cd <process_function_args+0x12d>
lea    0xd74(%rip),%rdi
call   1070 <printf@plt>
cmpl   $0x0,-0x68(%rbp)
je     1346 <process_function_args+0x1a6>
lea    0xd6a(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x68(%rbp),%eax
jge    133a <process_function_args+0x19a>
movslq -0x64(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x2c,%eax
jne    1319 <process_function_args+0x179>
lea    0xd45(%rip),%rdi
call   1070 <printf@plt>
jmp    1327 <process_function_args+0x187>
movslq -0x64(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%edi
call   1040 <putchar@plt>
jmp    132c <process_function_args+0x18c>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    12ea <process_function_args+0x14a>
lea    0xd18(%rip),%rdi
call   1070 <printf@plt>
lea    0xd17(%rip),%rdi
call   1070 <printf@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_function_args>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r12
mov    %rdi,%r15
call   1060 <strlen@plt>
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1080 <assert@plt>
movl   $0x0,(%r12)
mov    %rsp,%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
mov    (%r12),%ebx
mov    %r15,%rdi
call   1060 <strlen@plt>
cmp    %eax,%ebx
jge    120d <process_function_args+0x6d>
nopl   0x0(%rax,%rax,1)
movslq (%r12),%rbx
cmpb   $0x29,(%rsp,%rbx,1)
je     120d <process_function_args+0x6d>
add    $0x1,%ebx
mov    %ebx,(%r12)
mov    %r15,%rdi
call   1060 <strlen@plt>
cmp    %eax,%ebx
jl     11f0 <process_function_args+0x50>
movslq (%r12),%rbx
cmpb   $0x29,(%rsp,%rbx,1)
jne    12cf <process_function_args+0x12f>
lea    0xdff(%rip),%rsi
mov    %rsp,%rdi
call   10c0 <strstr@plt>
test   %rax,%rax
je     1244 <process_function_args+0xa4>
lea    0xdf1(%rip),%rdi
call   1070 <printf@plt>
add    $0xfffffff9,%ebx
test   %ebx,%ebx
jne    1254 <process_function_args+0xb4>
jmp    12af <process_function_args+0x10f>
lea    0xdf1(%rip),%rdi
call   1070 <printf@plt>
test   %ebx,%ebx
je     12af <process_function_args+0x10f>
lea    0xded(%rip),%rdi
call   1070 <printf@plt>
test   %ebx,%ebx
jle    12a3 <process_function_args+0x103>
mov    %ebx,%r12d
xor    %ebx,%ebx
lea    0xde4(%rip),%r15
jmp    1291 <process_function_args+0xf1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
call   1040 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
je     12a3 <process_function_args+0x103>
movzbl (%rsp,%rbx,1),%eax
cmp    $0x2c,%al
jne    1280 <process_function_args+0xe0>
mov    %r15,%rdi
call   1070 <printf@plt>
jmp    1288 <process_function_args+0xe8>
lea    0xdaf(%rip),%rdi
call   1070 <printf@plt>
lea    0xdae(%rip),%rdi
call   1070 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd21(%rip),%rsi
mov    %r14,%rdx
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Malformed function arguments %s\0A\00"
@.str.1 = [6 x i8] c". . .\00"
@.str.2 = [21 x i8] c"a variadic function \00"
@.str.3 = [12 x i8] c"a function \00"
@.str.4 = [12 x i8] c"that takes \00"
@.str.5 = [5 x i8] c" and\00"
@.str.6 = [11 x i8] c" args and \00"
@.str.7 = [14 x i8] c"that returns \00"
define void @process_function_args(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [64 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %6
%14 = load i8*, i8** %6
store i8* %14, i8** %7
store i32 0, i32* %9
%15 = load i8*, i8** %3
%16 = call i32 @assert(i8* %15)
%17 = load i32*, i32** %4
store i32 0, i32* %17
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = call i32 @strcpy(i8* %18, i8* %19)
br label %21
21: ; preds = %37, %2
%22 = load i32*, i32** %4
%23 = load i32, i32* %22
%24 = load i8*, i8** %3
%25 = call i32 @strlen(i8* %24)
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %35
27: ; preds = %21
%28 = load i32*, i32** %4
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 41
br label %35
35: ; preds = %27, %21
%36 = phi i1 [ false, %21 ], [ %34, %27 ]
br i1 %36, label %37, label %41
37: ; preds = %35
%38 = load i32*, i32** %4
%39 = load i32, i32* %38
%40 = add nsw i32 %39, 1
store i32 %40, i32* %38
br label %21
41: ; preds = %35
%42 = load i32*, i32** %4
%43 = load i32, i32* %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 41
br i1 %48, label %49, label %54
49: ; preds = %41
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %6
%52 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %51)
%53 = call i32 @exit(i32 -1)
unreachable
54: ; preds = %41
%55 = load i32*, i32** %4
%56 = load i32, i32* %55
store i32 %56, i32* %9
%57 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%58 = call i64 @strstr(i8* %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %54
%61 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%62 = load i32, i32* %9
%63 = sub nsw i32 %62, 7
store i32 %63, i32* %9
br label %66
64: ; preds = %54
%65 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %66
66: ; preds = %64, %60
%67 = load i32, i32* %9
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %96
69: ; preds = %66
%70 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %8
br label %71
71: ; preds = %91, %69
%72 = load i32, i32* %8
%73 = load i32, i32* %9
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %94
75: ; preds = %71
%76 = load i32, i32* %8
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %77
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 44
br i1 %81, label %82, label %84
82: ; preds = %75
%83 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %90
84: ; preds = %75
%85 = load i32, i32* %8
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 %86
%88 = load i8, i8* %87
%89 = call i32 @putchar(i8 signext %88)
br label %90
90: ; preds = %84, %82
br label %91
91: ; preds = %90
%92 = load i32, i32* %8
%93 = add nsw i32 %92, 1
store i32 %93, i32* %8
br label %71
94: ; preds = %71
%95 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %96
96: ; preds = %94, %66
%97 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%98 = load i8*, i8** %7
%99 = call i32 @free(i8* %98)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Malformed function arguments %s\0A\00"
@.str.1 = [6 x i8] c". . .\00"
@.str.2 = [21 x i8] c"a variadic function \00"
@.str.3 = [12 x i8] c"a function \00"
@.str.4 = [12 x i8] c"that takes \00"
@.str.5 = [5 x i8] c" and\00"
@.str.6 = [11 x i8] c" args and \00"
@.str.7 = [14 x i8] c"that returns \00"
define void @process_function_args(i8* %0, i32* nocapture %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @assert(i8* %0)
store i32 0, i32* %1
%9 = call i32 @strcpy(i8* %4, i8* %0)
%10 = load i32, i32* %1
%11 = call i32 @strlen(i8* %0)
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %23
13: ; preds = %2, %19
%14 = load i32, i32* %1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 41
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = add nsw i32 %14, 1
store i32 %20, i32* %1
%21 = call i32 @strlen(i8* %0)
%22 = icmp slt i32 %20, %21
br i1 %22, label %13, label %23
23: ; preds = %13, %19, %2
%24 = load i32, i32* %1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 41
br i1 %28, label %33, label %29
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %7)
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %23
%34 = call i64 @strstr(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%38 = add nsw i32 %24, -7
br label %41
39: ; preds = %33
%40 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
%42 = phi i32 [ %38, %36 ], [ %24, %39 ]
%43 = icmp eq i32 %42, 0
br i1 %43, label %63, label %44
44: ; preds = %41
%45 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp sgt i32 %42, 0
br i1 %46, label %47, label %61
47: ; preds = %44
%48 = zext i32 %42 to i64
br label %49
49: ; preds = %47, %58
%50 = phi i64 [ 0, %47 ], [ %59, %58 ]
%51 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, 44
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %58
56: ; preds = %49
%57 = call i32 @putchar(i8 signext %52)
br label %58
58: ; preds = %54, %56
%59 = add nuw nsw i64 %50, 1
%60 = icmp eq i64 %59, %48
br i1 %60, label %61, label %49
61: ; preds = %58, %44
%62 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %63
63: ; preds = %61, %41
%64 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%65 = call i32 @free(i8* %7)
ret void
}