int main() {
  int s1_size = 50;
  int s2_size = 100;
  char s1[s1_size];
  char *s2 = calloc(s2_size, sizeof(char));
  int i = 0;
  int isillegal = 0;
  init_string(s1, s1_size);
  init_string(s2, s2_size);
  i = read_str(s1, &s1_size);
  s1[i] = '\0';
  if (!(isillegal = check_legal(s1, i))) {
    expand(s1, s2, i, s2_size);
    if (0) {
      printf("%s\n", s1);
    }
    printf("%s\n", s2);
  } else {
    printf("Error: illegal input in function %s\n", __FUNCTION__);
    printf("Quitting");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x32,-0x8(%rbp)
movl   $0x64,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movslq -0xc(%rbp),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%esi
mov    $0x0,%al
call   1080 <init_string@plt>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x0,%al
call   1080 <init_string@plt>
mov    -0x40(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <read_str@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
mov    -0x2c(%rbp),%esi
mov    $0x0,%al
call   1070 <check_legal@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jne    123f <main+0xdf>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    $0x0,%al
call   1060 <expand@plt>
mov    -0x28(%rbp),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1275 <main+0x115>
lea    0xdba(%rip),%rdi
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1283 <main+0x123>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rsp,%r12
movl   $0x32,0xc(%rsp)
mov    $0x64,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
xor    %r14d,%r14d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x32,%esi
xor    %eax,%eax
call   1090 <init_string@plt>
mov    %r15,%rdi
mov    $0x64,%esi
xor    %eax,%eax
call   1090 <init_string@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <read_str@plt>
mov    %eax,%ebp
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <check_legal@plt>
test   %eax,%eax
je     1212 <main+0xa2>
lea    0xe12(%rip),%rdi
lea    0xe30(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe27(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
jmp    1230 <main+0xc0>
lea    0x10(%rsp),%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    $0x64,%ecx
xor    %eax,%eax
call   1070 <expand@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rsp
mov    %r14d,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [37 x i8] c"Error: illegal input in function %s\0A\00"
@__FUNCTION__.main = [5 x i8] c"main\00"
@.str.2 = [9 x i8] c"Quitting\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 50, i32* %2
store i32 100, i32* %3
%10 = load i32, i32* %2
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %4
%13 = alloca i8, i64 %11
store i64 %11, i64* %5
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = call i8* @calloc(i64 %15, i64 1)
store i8* %16, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
%17 = load i32, i32* %2
%18 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @init_string to i32 (i8*, i32, ...)*)(i8* %13, i32 %17)
%19 = load i8*, i8** %6
%20 = load i32, i32* %3
%21 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @init_string to i32 (i8*, i32, ...)*)(i8* %19, i32 %20)
%22 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @read_str to i32 (i8*, i32*, ...)*)(i8* %13, i32* %2)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %13, i64 %24
store i8 0, i8* %25
%26 = load i32, i32* %7
%27 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @check_legal to i32 (i8*, i32, ...)*)(i8* %13, i32 %26)
store i32 %27, i32* %8
%28 = icmp ne i32 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %0
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = load i32, i32* %3
%33 = call i32 (i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @expand to i32 (i8*, i8*, i32, i32, ...)*)(i8* %13, i8* %30, i32 %31, i32 %32)
%34 = load i8*, i8** %6
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %34)
br label %39
36: ; preds = %0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__FUNCTION__.main, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
store i32 1, i32* %9
br label %40
39: ; preds = %29
store i32 0, i32* %1
store i32 1, i32* %9
br label %40
40: ; preds = %39, %36
%41 = load i8*, i8** %4
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str.1 = [37 x i8] c"Error: illegal input in function %s\0A\00"
@__FUNCTION__.main = [5 x i8] c"main\00"
@.str.2 = [9 x i8] c"Quitting\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 50, i32* %1
%3 = tail call i8* @llvm.stacksave()
%4 = alloca [50 x i8]
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%6 = tail call dereferenceable_or_null(100) i8* @calloc(i64 100, i64 1)
%7 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @init_string to i32 (i8*, i32, ...)*)(i8* %5, i32 50)
%8 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @init_string to i32 (i8*, i32, ...)*)(i8* %6, i32 100)
%9 = call i32 (i8*, i32*, ...) bitcast (i32 (...)* @read_str to i32 (i8*, i32*, ...)*)(i8* %5, i32* %1)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @check_legal to i32 (i8*, i32, ...)*)(i8* %5, i32 %9)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 (i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @expand to i32 (i8*, i8*, i32, i32, ...)*)(i8* %5, i8* %6, i32 %9, i32 100)
%16 = call i32 @puts(i8* dereferenceable(1) %6)
br label %20
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__FUNCTION__.main, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %14, %17
%21 = phi i32 [ 1, %17 ], [ 0, %14 ]
ret i32 %21
}