#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*/ diagnostics(int, char *, char *, ...);
int /*<<< orphan*/ free(char *);
char *getBraceParam();
int getCounter(char *);
int /*<<< orphan*/ setCounter(char *, int);
int sscanf(char *, char *, int *);
char *strchr(char *, char);
void CmdCounter(int code) {
  char *s, *s2, *s3, *s4;
  int num;
  s = getBraceParam();
  diagnostics(4, "Entering CmdCounter(), <%s>", s);
  if (code == 3 || code == 2) {
    s2 = getBraceParam();
    if ((s3 = strchr(s2, '{')) && (s4 = strchr(s2, '}'))) {
      s3++;
      *s4 = '\0';
      diagnostics(4, "CmdCounter() processing \\value{%s}", s3);
      num = getCounter(s3);
    } else if (sscanf(s2, "%d", &num) != 1) {
      diagnostics(1, "\nBad parameter in set/addcounter{%s}{%s}", s, s2);
      free(s2);
      free(s);
      return;
    }
    free(s2);
    if (code == 3)
      setCounter(s, getCounter(s) + num);
    else
      setCounter(s, num);
  } else if (code == 1)
    setCounter(s, 0);
  free(s);
}


x86 assembly (clang, -O0):
<CmdCounter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getBraceParam@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
mov    $0x4,%edi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1060 <diagnostics@plt>
cmpl   $0x3,-0x4(%rbp)
je     11b1 <CmdCounter+0x41>
cmpl   $0x2,-0x4(%rbp)
jne    12cb <CmdCounter+0x15b>
mov    $0x0,%al
call   1040 <getBraceParam@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x7b,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     122f <CmdCounter+0xbf>
mov    -0x18(%rbp),%rdi
mov    $0x7d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     122f <CmdCounter+0xbf>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdx
mov    $0x4,%edi
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1060 <diagnostics@plt>
mov    -0x20(%rbp),%rdi
call   1080 <getCounter@plt>
mov    %eax,-0x2c(%rbp)
jmp    1283 <CmdCounter+0x113>
mov    -0x18(%rbp),%rdi
lea    0xe05(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
je     127e <CmdCounter+0x10e>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%edi
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1060 <diagnostics@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    12ee <CmdCounter+0x17e>
jmp    1283 <CmdCounter+0x113>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x3,-0x4(%rbp)
jne    12ba <CmdCounter+0x14a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <getCounter@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
add    -0x2c(%rbp),%esi
call   1090 <setCounter@plt>
jmp    12c6 <CmdCounter+0x156>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1090 <setCounter@plt>
jmp    12e5 <CmdCounter+0x175>
cmpl   $0x1,-0x4(%rbp)
jne    12e0 <CmdCounter+0x170>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1090 <setCounter@plt>
jmp    12e5 <CmdCounter+0x175>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CmdCounter>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %eax,%eax
call   1040 <getBraceParam@plt>
mov    %rax,%r15
lea    0xe76(%rip),%rsi
mov    $0x4,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <diagnostics@plt>
mov    %ebp,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    11ff <CmdCounter+0x8f>
xor    %eax,%eax
call   1040 <getBraceParam@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x7b,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     120b <CmdCounter+0x9b>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x7d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     120b <CmdCounter+0x9b>
add    $0x1,%rbx
movb   $0x0,(%rax)
lea    0xe3a(%rip),%rsi
mov    $0x4,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <diagnostics@plt>
mov    %rbx,%rdi
call   1080 <getCounter@plt>
mov    %eax,0x4(%rsp)
jmp    1224 <CmdCounter+0xb4>
cmp    $0x1,%ebp
jne    1273 <CmdCounter+0x103>
mov    %r15,%rdi
xor    %esi,%esi
jmp    124b <CmdCounter+0xdb>
lea    0xe2d(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1252 <CmdCounter+0xe2>
mov    %r14,%rdi
call   1030 <free@plt>
cmp    $0x3,%ebp
jne    1244 <CmdCounter+0xd4>
mov    %r15,%rdi
call   1080 <getCounter@plt>
add    0x4(%rsp),%eax
mov    %r15,%rdi
mov    %eax,%esi
jmp    124b <CmdCounter+0xdb>
mov    0x4(%rsp),%esi
mov    %r15,%rdi
call   1090 <setCounter@plt>
jmp    1273 <CmdCounter+0x103>
lea    0xde9(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <diagnostics@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Entering CmdCounter(), <%s>\00"
@.str.1 = [35 x i8] c"CmdCounter() processing \\value{%s}\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [41 x i8] c"\0ABad parameter in set/addcounter{%s}{%s}\00"
define void @CmdCounter(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %2
%8 = call i8* (...) @getBraceParam()
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 (i32, i8*, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 3
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %63
16: ; preds = %13, %1
%17 = call i8* (...) @getBraceParam()
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = call i8* @strchr(i8* %18, i8 signext 123)
store i8* %19, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %33
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = call i8* @strchr(i8* %22, i8 signext 125)
store i8* %23, i8** %6
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
%28 = load i8*, i8** %6
store i8 0, i8* %28
%29 = load i8*, i8** %5
%30 = call i32 (i32, i8*, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %5
%32 = call i32 @getCounter(i8* %31)
store i32 %32, i32* %7
br label %46
33: ; preds = %21, %16
%34 = load i8*, i8** %4
%35 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %45
37: ; preds = %33
%38 = load i8*, i8** %3
%39 = load i8*, i8** %4
%40 = call i32 (i32, i8*, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %38, i8* %39)
%41 = load i8*, i8** %4
%42 = call i32 @free(i8* %41)
%43 = load i8*, i8** %3
%44 = call i32 @free(i8* %43)
br label %73
45: ; preds = %33
br label %46
46: ; preds = %45, %25
%47 = load i8*, i8** %4
%48 = call i32 @free(i8* %47)
%49 = load i32, i32* %2
%50 = icmp eq i32 %49, 3
br i1 %50, label %51, label %58
51: ; preds = %46
%52 = load i8*, i8** %3
%53 = load i8*, i8** %3
%54 = call i32 @getCounter(i8* %53)
%55 = load i32, i32* %7
%56 = add nsw i32 %54, %55
%57 = call i32 @setCounter(i8* %52, i32 %56)
br label %62
58: ; preds = %46
%59 = load i8*, i8** %3
%60 = load i32, i32* %7
%61 = call i32 @setCounter(i8* %59, i32 %60)
br label %62
62: ; preds = %58, %51
br label %70
63: ; preds = %13
%64 = load i32, i32* %2
%65 = icmp eq i32 %64, 1
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = load i8*, i8** %3
%68 = call i32 @setCounter(i8* %67, i32 0)
br label %69
69: ; preds = %66, %63
br label %70
70: ; preds = %69, %62
%71 = load i8*, i8** %3
%72 = call i32 @free(i8* %71)
br label %73
73: ; preds = %70, %37
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"Entering CmdCounter(), <%s>\00"
@.str.1 = [35 x i8] c"CmdCounter() processing \\value{%s}\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [41 x i8] c"\0ABad parameter in set/addcounter{%s}{%s}\00"
define void @CmdCounter(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i8* (...) @getBraceParam()
%5 = tail call i32 (i32, i8*, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = icmp eq i32 %0, 3
%7 = and i32 %0, -2
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %36
9: ; preds = %1
%10 = tail call i8* (...) @getBraceParam()
%11 = tail call i8* @strchr(i8* dereferenceable(1) %10, i8 signext 123)
%12 = icmp eq i8* %11, null
br i1 %12, label %20, label %13
13: ; preds = %9
%14 = tail call i8* @strchr(i8* dereferenceable(1) %10, i8 signext 125)
%15 = icmp eq i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %11, i64 1
store i8 0, i8* %14
%18 = tail call i32 (i32, i8*, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = tail call i32 @getCounter(i8* %17)
store i32 %19, i32* %2
br label %26
20: ; preds = %13, %9
%21 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%22 = icmp eq i32 %21, 1
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = call i32 (i32, i8*, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* %10)
%25 = call i32 @free(i8* %10)
br label %40
26: ; preds = %20, %16
%27 = call i32 @free(i8* %10)
br i1 %6, label %28, label %33
28: ; preds = %26
%29 = call i32 @getCounter(i8* %4)
%30 = load i32, i32* %2
%31 = add nsw i32 %30, %29
%32 = call i32 @setCounter(i8* %4, i32 %31)
br label %40
33: ; preds = %26
%34 = load i32, i32* %2
%35 = call i32 @setCounter(i8* %4, i32 %34)
br label %40
36: ; preds = %1
%37 = icmp eq i32 %0, 1
br i1 %37, label %38, label %40
38: ; preds = %36
%39 = tail call i32 @setCounter(i8* %4, i32 0)
br label %40
40: ; preds = %33, %28, %38, %36, %23
%41 = call i32 @free(i8* %4)
ret void
}