#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;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  char ch, file_name[25];
  FILE *fp;
  int i = 0, totaltotal = 0;
  ;
  for (i = 1; i < argc; ++i) {
    printf(argv[i]);
    fp = fopen(argv[i], "r");
    if (fp == NULL) {
      perror("Error while opening the file.\n");
      exit(EXIT_FAILURE);
    }
    int i = 1, total = 0;
    while ((ch = fgetc(fp)) != EOF) {
      if (ch == '{')
        i++;
      else if (ch == '}')
        i--;
      else if (ch == ';')
        total += i;
    }
    fclose(fp);
    printf("result: %d\n", total);
    totaltotal += total;
  }
  printf("total: %d\n", totaltotal);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12a6 <main+0x146>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe43(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11eb <main+0x8b>
lea    0xe2a(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x1,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2dd9(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1275 <main+0x115>
movsbl -0x11(%rbp),%eax
cmp    $0x7b,%eax
jne    1235 <main+0xd5>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1270 <main+0x110>
movsbl -0x11(%rbp),%eax
cmp    $0x7d,%eax
jne    1250 <main+0xf0>
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    126b <main+0x10b>
movsbl -0x11(%rbp),%eax
cmp    $0x3b,%eax
jne    1266 <main+0x106>
mov    -0x44(%rbp),%eax
add    -0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    126b <main+0x10b>
jmp    1270 <main+0x110>
jmp    11f9 <main+0x99>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x48(%rbp),%esi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    118b <main+0x2b>
mov    -0x40(%rbp),%esi
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
xor    %r13d,%r13d
cmp    $0x2,%edi
jl     1246 <main+0xe6>
mov    %edi,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%r15d
mov    0x2e55(%rip),%r14
xor    %r13d,%r13d
jmp    11ca <main+0x6a>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe72(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    %ebp,%r13d
add    $0x1,%r15
cmp    0x8(%rsp),%r15
je     1246 <main+0xe6>
mov    0x10(%rsp),%rbx
mov    (%rbx,%r15,8),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx,%r15,8),%rdi
lea    0xe1b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1268 <main+0x108>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
xor    %ebp,%ebp
cmp    (%r14),%al
je     11a0 <main+0x40>
mov    $0x1,%r12d
xor    %ebp,%ebp
jmp    1220 <main+0xc0>
nopl   0x0(%rax,%rax,1)
add    %r12d,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%al
je     11a0 <main+0x40>
cmp    $0x3b,%al
je     1210 <main+0xb0>
cmp    $0x7d,%al
je     1240 <main+0xe0>
cmp    $0x7b,%al
jne    1213 <main+0xb3>
add    $0x1,%r12d
jmp    1213 <main+0xb3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffff,%r12d
jmp    1213 <main+0xb3>
lea    0xde0(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd93(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"Error while opening the file.\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@.str.2 = [12 x i8] c"result: %d\0A\00"
@.str.3 = [11 x i8] c"total: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca [25 x i8]
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
store i32 0, i32* %10
store i32 1, i32* %9
br label %13
13: ; preds = %77, %2
%14 = load i32, i32* %9
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %80
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* %22)
%24 = load i8**, i8*** %5
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %8
%30 = load i32*, i32** %8
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %36
32: ; preds = %17
%33 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %17
store i32 1, i32* %11
store i32 0, i32* %12
br label %37
37: ; preds = %68, %36
%38 = load i32*, i32** %8
%39 = call signext i8 @fgetc(i32* %38)
store i8 %39, i8* %6
%40 = sext i8 %39 to i32
%41 = load i8, i8* @EOF
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %40, %42
br i1 %43, label %44, label %69
44: ; preds = %37
%45 = load i8, i8* %6
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 123
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i32, i32* %11
%50 = add nsw i32 %49, 1
store i32 %50, i32* %11
br label %68
51: ; preds = %44
%52 = load i8, i8* %6
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 125
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = load i32, i32* %11
%57 = add nsw i32 %56, -1
store i32 %57, i32* %11
br label %67
58: ; preds = %51
%59 = load i8, i8* %6
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 59
br i1 %61, label %62, label %66
62: ; preds = %58
%63 = load i32, i32* %11
%64 = load i32, i32* %12
%65 = add nsw i32 %64, %63
store i32 %65, i32* %12
br label %66
66: ; preds = %62, %58
br label %67
67: ; preds = %66, %55
br label %68
68: ; preds = %67, %48
br label %37
69: ; preds = %37
%70 = load i32*, i32** %8
%71 = call i32 @fclose(i32* %70)
%72 = load i32, i32* %12
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %72)
%74 = load i32, i32* %12
%75 = load i32, i32* %10
%76 = add nsw i32 %75, %74
store i32 %76, i32* %10
br label %77
77: ; preds = %69
%78 = load i32, i32* %9
%79 = add nsw i32 %78, 1
store i32 %79, i32* %9
br label %13
80: ; preds = %13
%81 = load i32, i32* %10
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %81)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"Error while opening the file.\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@.str.2 = [12 x i8] c"result: %d\0A\00"
@.str.3 = [11 x i8] c"total: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %46
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %39
%7 = phi i64 [ 1, %4 ], [ %44, %39 ]
%8 = phi i32 [ 0, %4 ], [ %43, %39 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %7
%10 = load i8*, i8** %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %10)
%12 = load i8*, i8** %9
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %19, label %15
15: ; preds = %6
%16 = tail call signext i8 @fgetc(i32* %13)
%17 = load i8, i8* @EOF
%18 = icmp eq i8 %16, %17
br i1 %18, label %39, label %23
19: ; preds = %6
%20 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %15, %33
%24 = phi i8 [ %36, %33 ], [ %16, %15 ]
%25 = phi i32 [ %35, %33 ], [ 0, %15 ]
%26 = phi i32 [ %34, %33 ], [ 1, %15 ]
switch i8 %24, label %33 [
i8 123, label %27
i8 125, label %29
i8 59, label %31
]
27: ; preds = %23
%28 = add nsw i32 %26, 1
br label %33
29: ; preds = %23
%30 = add nsw i32 %26, -1
br label %33
31: ; preds = %23
%32 = add nsw i32 %25, %26
br label %33
33: ; preds = %23, %29, %31, %27
%34 = phi i32 [ %28, %27 ], [ %30, %29 ], [ %26, %31 ], [ %26, %23 ]
%35 = phi i32 [ %25, %27 ], [ %25, %29 ], [ %32, %31 ], [ %25, %23 ]
%36 = tail call signext i8 @fgetc(i32* %13)
%37 = load i8, i8* @EOF
%38 = icmp eq i8 %36, %37
br i1 %38, label %39, label %23
39: ; preds = %33, %15
%40 = phi i32 [ 0, %15 ], [ %35, %33 ]
%41 = tail call i32 @fclose(i32* %13)
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%43 = add nsw i32 %40, %8
%44 = add nuw nsw i64 %7, 1
%45 = icmp eq i64 %44, %5
br i1 %45, label %46, label %6
46: ; preds = %39, %2
%47 = phi i32 [ 0, %2 ], [ %43, %39 ]
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %47)
ret i32 0
}