#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 getchar();
int /*<<< orphan*/ gettoken();
int /*<<< orphan*/ printf(char *, char *);
void read_array_size(void) {
  char buf[50];
  int c, i = 0;
  while ((c = getchar()) != ']' && i < 50 - 1)
    buf[i++] = c;
  buf[i] = '\0';
  gettoken();
  printf("array of %s ", buf);
}


x86 assembly (clang, -O0):
<read_array_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x48(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
xor    %eax,%eax
cmp    $0x5d,%ecx
mov    %al,-0x49(%rbp)
je     1163 <read_array_size+0x33>
cmpl   $0x31,-0x48(%rbp)
setl   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1173 <read_array_size+0x43>
jmp    118e <read_array_size+0x5e>
mov    -0x44(%rbp),%eax
mov    %al,%cl
mov    -0x48(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x48(%rbp)
cltq
mov    %cl,-0x40(%rbp,%rax,1)
jmp    113f <read_array_size+0xf>
movslq -0x48(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    $0x0,%al
call   1030 <gettoken@plt>
lea    -0x40(%rbp),%rsi
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_array_size>:
push   %r14
push   %rbx
sub    $0x38,%rsp
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x5d,%eax
je     116c <read_array_size+0x3c>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r14
mov    %al,(%rsp,%rbx,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x5d,%eax
je     116c <read_array_size+0x3c>
cmp    $0x30,%rbx
mov    %r14,%rbx
jb     1150 <read_array_size+0x20>
movb   $0x0,(%rsp,%r14,1)
xor    %eax,%eax
call   1030 <gettoken@plt>
lea    0xe81(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"array of %s \00"
define void @read_array_size() {
%1 = alloca [50 x i8]
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
br label %4
4: ; preds = %12, %0
%5 = call i32 (...) @getchar()
store i32 %5, i32* %2
%6 = icmp ne i32 %5, 93
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 49
br label %10
10: ; preds = %7, %4
%11 = phi i1 [ false, %4 ], [ %9, %7 ]
br i1 %11, label %12, label %19
12: ; preds = %10
%13 = load i32, i32* %2
%14 = trunc i32 %13 to i8
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %17
store i8 %14, i8* %18
br label %4
19: ; preds = %10
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i32 (...) @gettoken()
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %24)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"array of %s \00"
define void @read_array_size() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @getchar()
%4 = icmp eq i32 %3, 93
br i1 %4, label %15, label %5
5: ; preds = %0, %5
%6 = phi i64 [ %9, %5 ], [ 0, %0 ]
%7 = phi i32 [ %11, %5 ], [ %3, %0 ]
%8 = trunc i32 %7 to i8
%9 = add nuw nsw i64 %6, 1
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %6
store i8 %8, i8* %10
%11 = tail call i32 (...) @getchar()
%12 = icmp ne i32 %11, 93
%13 = icmp ult i64 %6, 48
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %5, label %15
15: ; preds = %5, %0
%16 = phi i64 [ 0, %0 ], [ %9, %5 ]
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %16
store i8 0, i8* %17
%18 = tail call i32 (...) @gettoken()
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %2)
ret void
}