#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 */
scalar_t__ calloc(int, int);
scalar_t__ checkExpression(char *);
int /*<<< orphan*/ exitError(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
void readExpression(char **values, int *size) {
  fprintf(stdout, "[INFO] [READ]\tIntroduce the mathematical expression "
                  "separated by space in\n");
  fprintf(stdout,
          "\t\tpostfix form with operands in [a-zA-Z], operations in '+-*/'\n");
  fprintf(stdout, "\t\tand use '#' for unary operations:\n");
  fprintf(stdout, "[INFO] [READ]\t");
  char *buffer = (char *)calloc(1024, sizeof(char));
  fgets(buffer, 1024, stdin);
  *size = 0;
  while (*(buffer + *size) != '\n') {
    (*size)++;
  }
  *size = (*size + 1) / 2;
  char *result = (char *)calloc((*size + 1), sizeof(char));
  for (int i = 0; i < *size; i++) {
    *(result + i) = *(buffer + i * 2);
  }
  free(buffer);
  if (checkExpression(result)) {
    *values = result;
  } else {
    exitError("[READ]\tThe read expression contains invalid characters.\n");
  }
}


x86 assembly (clang, -O0):
<readExpression>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xee1(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xef1(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x400,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1220 <readExpression+0xc0>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11f8 <readExpression+0x98>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    128f <readExpression+0x12f>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1257 <readExpression+0xf7>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1080 <checkExpression@plt>
cmp    $0x0,%rax
je     12bb <readExpression+0x15b>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    12c7 <readExpression+0x167>
lea    0xdfd(%rip),%rdi
call   1040 <exitError@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readExpression>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e63(%rip),%rbx
mov    (%rbx),%edi
lea    0xe82(%rip),%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xebf(%rip),%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xef1(%rip),%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xf08(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x400,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1050 <fgets@plt>
xor    %edi,%edi
nopw   0x0(%rax,%rax,1)
mov    %edi,(%r15)
cmpb   $0xa,(%rbx,%rdi,1)
lea    0x1(%rdi),%rdi
jne    11e0 <readExpression+0x80>
shr    %edi
mov    %edi,(%r15)
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
cmpl   $0x0,(%r15)
jle    1224 <readExpression+0xc4>
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rax,2),%ecx
mov    %cl,(%r12,%rax,1)
add    $0x1,%rax
movslq (%r15),%rcx
cmp    %rcx,%rax
jl     1210 <readExpression+0xb0>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1080 <checkExpression@plt>
test   %rax,%rax
je     1248 <readExpression+0xe8>
mov    %r12,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe70(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <exitError@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [75 x i8] c"[INFO] [READ]\09Introduce the mathematical expression separated by space in\0A\00"
@.str.1 = [64 x i8] c"\09\09postfix form with operands in [a-zA-Z], operations in '+-*/'\0A\00"
@.str.2 = [37 x i8] c"\09\09and use '#' for unary operations:\0A\00"
@.str.3 = [15 x i8] c"[INFO] [READ]\09\00"
@stdin = global i32 0
@.str.4 = [57 x i8] c"[READ]\09The read expression contains invalid characters.\0A\00"
define void @readExpression(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8** %0, i8*** %3
store i32* %1, i32** %4
%8 = load i32, i32* @stdout
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stdout
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @stdout
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @stdout
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%16 = call i64 @calloc(i32 1024, i32 1)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %18, i32 1024, i32 %19)
%21 = load i32*, i32** %4
store i32 0, i32* %21
br label %22
22: ; preds = %31, %2
%23 = load i8*, i8** %5
%24 = load i32*, i32** %4
%25 = load i32, i32* %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 10
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = load i32*, i32** %4
%33 = load i32, i32* %32
%34 = add nsw i32 %33, 1
store i32 %34, i32* %32
br label %22
35: ; preds = %22
%36 = load i32*, i32** %4
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
%39 = sdiv i32 %38, 2
%40 = load i32*, i32** %4
store i32 %39, i32* %40
%41 = load i32*, i32** %4
%42 = load i32, i32* %41
%43 = add nsw i32 %42, 1
%44 = call i64 @calloc(i32 %43, i32 1)
%45 = inttoptr i64 %44 to i8*
store i8* %45, i8** %6
store i32 0, i32* %7
br label %46
46: ; preds = %62, %35
%47 = load i32, i32* %7
%48 = load i32*, i32** %4
%49 = load i32, i32* %48
%50 = icmp slt i32 %47, %49
br i1 %50, label %51, label %65
51: ; preds = %46
%52 = load i8*, i8** %5
%53 = load i32, i32* %7
%54 = mul nsw i32 %53, 2
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
%57 = load i8, i8* %56
%58 = load i8*, i8** %6
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 %57, i8* %61
br label %62
62: ; preds = %51
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 1
store i32 %64, i32* %7
br label %46
65: ; preds = %46
%66 = load i8*, i8** %5
%67 = call i32 @free(i8* %66)
%68 = load i8*, i8** %6
%69 = call i64 @checkExpression(i8* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %65
%72 = load i8*, i8** %6
%73 = load i8**, i8*** %3
store i8* %72, i8** %73
br label %76
74: ; preds = %65
%75 = call i32 @exitError(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0))
br label %76
76: ; preds = %74, %71
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [75 x i8] c"[INFO] [READ]\09Introduce the mathematical expression separated by space in\0A\00"
@.str.1 = [64 x i8] c"\09\09postfix form with operands in [a-zA-Z], operations in '+-*/'\0A\00"
@.str.2 = [37 x i8] c"\09\09and use '#' for unary operations:\0A\00"
@.str.3 = [15 x i8] c"[INFO] [READ]\09\00"
@stdin = global i32 0
@.str.4 = [57 x i8] c"[READ]\09The read expression contains invalid characters.\0A\00"
define void @readExpression(i8** nocapture writeonly %0, i32* nocapture %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 @fprintf(i32 %3, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdout
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @stdout
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @stdout
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i64 @calloc(i32 1024, i32 1)
%12 = inttoptr i64 %11 to i8*
%13 = load i32, i32* @stdin
%14 = tail call i32 @fgets(i8* %12, i32 1024, i32 %13)
br label %15
15: ; preds = %15, %2
%16 = phi i64 [ %21, %15 ], [ 0, %2 ]
%17 = trunc i64 %16 to i32
store i32 %17, i32* %1
%18 = getelementptr inbounds i8, i8* %12, i64 %16
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
%21 = add nuw i64 %16, 1
br i1 %20, label %22, label %15
22: ; preds = %15
%23 = trunc i64 %16 to i32
%24 = add nuw nsw i32 %23, 1
%25 = lshr i32 %24, 1
store i32 %25, i32* %1
%26 = add nuw nsw i32 %25, 1
%27 = tail call i64 @calloc(i32 %26, i32 1)
%28 = inttoptr i64 %27 to i8*
%29 = load i32, i32* %1
%30 = icmp sgt i32 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %35, %22
%32 = tail call i32 @free(i8* %12)
%33 = tail call i64 @checkExpression(i8* %28)
%34 = icmp eq i64 %33, 0
br i1 %34, label %46, label %45
35: ; preds = %22, %35
%36 = phi i64 [ %41, %35 ], [ 0, %22 ]
%37 = shl nuw nsw i64 %36, 1
%38 = getelementptr inbounds i8, i8* %12, i64 %37
%39 = load i8, i8* %38
%40 = getelementptr inbounds i8, i8* %28, i64 %36
store i8 %39, i8* %40
%41 = add nuw nsw i64 %36, 1
%42 = load i32, i32* %1
%43 = sext i32 %42 to i64
%44 = icmp slt i64 %41, %43
br i1 %44, label %35, label %31
45: ; preds = %31
store i8* %28, i8** %0
br label %48
46: ; preds = %31
%47 = tail call i32 @exitError(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %45
ret void
}