#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*/ exit(int);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
char *getExpressionFromArgs(int argc, char **argv) {
  if (argc < 2) {
    printf("\x1b[36m"
           "usage:\n\talgebra [expression]\n"
           "\x1b[0m");
    exit(1);
  }
  int totalBytesForExpression = 0;
  for (int i = 1; i < argc; i++) {
    totalBytesForExpression += strlen(argv[i]);
  }
  totalBytesForExpression += (argc - 1);
  char *mainExpression = malloc(sizeof(char) * totalBytesForExpression);
  for (int i = 1; i < argc; i++) {
    strcat(mainExpression, argv[i]);
  }
  strcat(mainExpression, ";");
  return mainExpression;
}


x86 assembly (clang, -O0):
<getExpressionFromArgs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
jge    117f <getExpressionFromArgs+0x2f>
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c5 <getExpressionFromArgs+0x75>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118d <getExpressionFromArgs+0x3d>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121a <getExpressionFromArgs+0xca>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11eb <getExpressionFromArgs+0x9b>
mov    -0x20(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getExpressionFromArgs>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%edi
jl     11d1 <getExpressionFromArgs+0x81>
mov    %rsi,%r12
mov    %edi,%r14d
mov    %edi,%r13d
xor    %r15d,%r15d
mov    $0x1,%ebx
nop
mov    (%r12,%rbx,8),%rdi
call   1030 <strlen@plt>
add    %eax,%r15d
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1170 <getExpressionFromArgs+0x20>
lea    (%r14,%r15,1),%edi
add    $0xffffffff,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
cmp    $0x2,%r14d
jl     11b5 <getExpressionFromArgs+0x65>
mov    $0x1,%ebx
nop
mov    (%r12,%rbx,8),%rsi
mov    %r15,%rdi
call   1060 <strcat@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11a0 <getExpressionFromArgs+0x50>
lea    0xe6b(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcat@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe28(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"\1B[36musage:\0A\09algebra [expression]\0A\1B[0m\00"
@.str.1 = [2 x i8] c";\00"
define i8* @getExpressionFromArgs(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
store i32 0, i32* %5
store i32 1, i32* %6
br label %15
15: ; preds = %30, %14
%16 = load i32, i32* %6
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = load i8**, i8*** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i64 @strlen(i8* %24)
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = add nsw i64 %27, %25
%29 = trunc i64 %28 to i32
store i32 %29, i32* %5
br label %30
30: ; preds = %19
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %15
33: ; preds = %15
%34 = load i32, i32* %3
%35 = sub nsw i32 %34, 1
%36 = load i32, i32* %5
%37 = add nsw i32 %36, %35
store i32 %37, i32* %5
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = mul i64 1, %39
%41 = trunc i64 %40 to i32
%42 = call i8* @malloc(i32 %41)
store i8* %42, i8** %7
store i32 1, i32* %8
br label %43
43: ; preds = %55, %33
%44 = load i32, i32* %8
%45 = load i32, i32* %3
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %58
47: ; preds = %43
%48 = load i8*, i8** %7
%49 = load i8**, i8*** %4
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 @strcat(i8* %48, i8* %53)
br label %55
55: ; preds = %47
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %43
58: ; preds = %43
%59 = load i8*, i8** %7
%60 = call i32 @strcat(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%61 = load i8*, i8** %7
ret i8* %61
}

LLVM IR (-O2):
@.str = [39 x i8] c"\1B[36musage:\0A\09algebra [expression]\0A\1B[0m\00"
@.str.1 = [2 x i8] c";\00"
define i8* @getExpressionFromArgs(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %16
6: ; preds = %2
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %16
%10 = add nsw i32 %0, -1
%11 = add nsw i32 %10, %23
%12 = tail call i8* @malloc(i32 %11)
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %26
14: ; preds = %9
%15 = zext i32 %0 to i64
br label %28
16: ; preds = %4, %16
%17 = phi i64 [ 1, %4 ], [ %24, %16 ]
%18 = phi i32 [ 0, %4 ], [ %23, %16 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %17
%20 = load i8*, i8** %19
%21 = tail call i64 @strlen(i8* dereferenceable(1) %20)
%22 = trunc i64 %21 to i32
%23 = add i32 %18, %22
%24 = add nuw nsw i64 %17, 1
%25 = icmp eq i64 %24, %5
br i1 %25, label %9, label %16
26: ; preds = %28, %9
%27 = tail call i32 @strcat(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i8* %12
28: ; preds = %14, %28
%29 = phi i64 [ 1, %14 ], [ %33, %28 ]
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = tail call i32 @strcat(i8* %12, i8* %31)
%33 = add nuw nsw i64 %29, 1
%34 = icmp eq i64 %33, %15
br i1 %34, label %26, label %28
}