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

/* Variables and functions */
char EOF;
char find_next_word(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int count_args(FILE *fileinp, int *nargs) {
  char stopchar;
  char buffer[1000];
  int lbuf;
  char name[100];
  int lname;
  int nnargs;
  *nargs = 1;
  while ((stopchar = find_next_word(fileinp, buffer, &lbuf)) != EOF) {
    printf("stop: %c \t word: %s (nargs=%d)\n", stopchar, buffer, *nargs);
    switch (stopchar) {
    case ',':
      (*nargs)++;
      printf("nargs = %d!\n", *nargs);
      break;
    case ')':
      printf("return!\n");
      return 0;
      break;
    case '(':
      if (lbuf != 0) {
        strcpy(name, buffer);
        lname = lbuf;
        printf("call count_args!\n");
        count_args(fileinp, &nnargs);
        printf("\t*** function : %s (%d args)\n", name, nnargs);
      }
      break;
    default:
      break;
    }
  }
}


x86 assembly (clang, -O0):
<count_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
lea    -0x414(%rbp),%rdx
call   1060 <find_next_word@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2e67(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     129d <count_args+0x15d>
movsbl -0x19(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
lea    0xe63(%rip),%rdi
xor    %eax,%eax
lea    -0x410(%rbp),%rdx
call   1050 <printf@plt>
movsbl -0x19(%rbp),%eax
mov    %eax,-0x48c(%rbp)
sub    $0x28,%eax
je     1229 <count_args+0xe9>
jmp    11c3 <count_args+0x83>
mov    -0x48c(%rbp),%eax
sub    $0x29,%eax
je     120f <count_args+0xcf>
jmp    11d7 <count_args+0x97>
mov    -0x48c(%rbp),%eax
sub    $0x2c,%eax
jne    1293 <count_args+0x153>
jmp    11eb <count_args+0xab>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1298 <count_args+0x158>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129d <count_args+0x15d>
cmpl   $0x0,-0x414(%rbp)
je     128e <count_args+0x14e>
lea    -0x480(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x414(%rbp),%eax
mov    %eax,-0x484(%rbp)
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x488(%rbp),%rsi
call   1040 <count_args@plt>
lea    -0x480(%rbp),%rsi
mov    -0x488(%rbp),%edx
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1298 <count_args+0x158>
jmp    1298 <count_args+0x158>
jmp    115d <count_args+0x1d>
mov    -0x4(%rbp),%eax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x468,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movl   $0x1,(%rsi)
lea    0x80(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1070 <find_next_word@plt>
mov    0x2e62(%rip),%rbp
cmp    0x0(%rbp),%al
je     125c <count_args+0x10c>
lea    0x80(%rsp),%r12
lea    0x8(%rsp),%r15
jmp    11cc <count_args+0x7c>
xchg   %ax,%ax
mov    (%rbx),%esi
add    $0x1,%esi
mov    %esi,(%rbx)
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1070 <find_next_word@plt>
cmp    0x0(%rbp),%al
je     125c <count_args+0x10c>
movsbl %al,%r13d
mov    (%rbx),%ecx
lea    0xe27(%rip),%rdi
mov    %r13d,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x28,%r13d
je     1200 <count_args+0xb0>
cmp    $0x2c,%r13d
je     11a0 <count_args+0x50>
cmp    $0x29,%r13d
jne    11b5 <count_args+0x65>
jmp    1250 <count_args+0x100>
nopw   0x0(%rax,%rax,1)
cmpl   $0x0,0x8(%rsp)
je     11b5 <count_args+0x65>
mov    %rbp,%r13
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
lea    0xe2a(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
lea    0xc(%rsp),%rsi
call   1050 <count_args@plt>
mov    0xc(%rsp),%edx
lea    0xdef(%rip),%rdi
mov    %rbp,%rsi
mov    %r13,%rbp
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11b5 <count_args+0x65>
lea    0xe05(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x468,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
@.str = [32 x i8] c"stop: %c \09 word: %s (nargs=%d)\0A\00"
@.str.1 = [13 x i8] c"nargs = %d!\0A\00"
@.str.2 = [9 x i8] c"return!\0A\00"
@.str.3 = [18 x i8] c"call count_args!\0A\00"
@.str.4 = [30 x i8] c"\09*** function : %s (%d args)\0A\00"
define i32 @count_args(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8
%7 = alloca [1000 x i8]
%8 = alloca i32
%9 = alloca [100 x i8]
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%12 = load i32*, i32** %5
store i32 1, i32* %12
br label %13
13: ; preds = %55, %2
%14 = load i32*, i32** %4
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%16 = call signext i8 @find_next_word(i32* %14, i8* %15, i32* %8)
store i8 %16, i8* %6
%17 = sext i8 %16 to i32
%18 = load i8, i8* @EOF
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %17, %19
br i1 %20, label %21, label %56
21: ; preds = %13
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%25 = load i32*, i32** %5
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %23, i8* %24, i32 %26)
%28 = load i8, i8* %6
%29 = sext i8 %28 to i32
switch i32 %29, label %54 [
i32 44, label %30
i32 41, label %37
i32 40, label %39
]
30: ; preds = %21
%31 = load i32*, i32** %5
%32 = load i32, i32* %31
%33 = add nsw i32 %32, 1
store i32 %33, i32* %31
%34 = load i32*, i32** %5
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %35)
br label %55
37: ; preds = %21
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %56
39: ; preds = %21
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %53
42: ; preds = %39
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%44 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%45 = call i32 @strcpy(i8* %43, i8* %44)
%46 = load i32, i32* %8
store i32 %46, i32* %10
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%48 = load i32*, i32** %4
%49 = call i32 @count_args(i32* %48, i32* %11)
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%51 = load i32, i32* %11
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %50, i32 %51)
br label %53
53: ; preds = %42, %39
br label %55
54: ; preds = %21
br label %55
55: ; preds = %54, %53, %30
br label %13
56: ; preds = %37, %13
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [32 x i8] c"stop: %c \09 word: %s (nargs=%d)\0A\00"
@.str.1 = [13 x i8] c"nargs = %d!\0A\00"
@.str.4 = [30 x i8] c"\09*** function : %s (%d args)\0A\00"
@str = [17 x i8] c"call count_args!\00"
@str.5 = [8 x i8] c"return!\00"
define i32 @count_args(i32* %0, i32* nocapture %1) {
%3 = alloca [1000 x i8]
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
store i32 1, i32* %1
%11 = call signext i8 @find_next_word(i32* %0, i8* %7, i32* %4)
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %11, %12
br i1 %13, label %38, label %14
14: ; preds = %2, %34
%15 = phi i8 [ %35, %34 ], [ %11, %2 ]
%16 = sext i8 %15 to i32
%17 = load i32, i32* %1
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %7, i32 %17)
switch i32 %16, label %34 [
i32 44, label %19
i32 41, label %23
i32 40, label %25
]
19: ; preds = %14
%20 = load i32, i32* %1
%21 = add nsw i32 %20, 1
store i32 %21, i32* %1
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %34
23: ; preds = %14
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.5, i64 0, i64 0))
br label %38
25: ; preds = %14
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %25
%29 = call i32 @strcpy(i8* %9, i8* %7)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%31 = call i32 @count_args(i32* %0, i32* %6)
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %9, i32 %32)
br label %34
34: ; preds = %14, %25, %28, %19
%35 = call signext i8 @find_next_word(i32* %0, i8* %7, i32* %4)
%36 = load i8, i8* @EOF
%37 = icmp eq i8 %35, %36
br i1 %37, label %38, label %14
38: ; preds = %34, %2, %23
ret i32 0
}