#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
char getc(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int shelly(char *);
int exec(FILE *f, size_t len) {
  char *b = (char *)malloc(len);
  char c, *s = b;
  int r;
  memset(b, 0, len);
  while ((c = getc(f)) > 0 && c != '!') {
    if (!len--) {
      free(s);
      exit(255);
    }
    *b++ = c;
  }
  r = shelly(s);
  free(s);
  return r;
}


x86 assembly (clang, -O0):
<exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1080 <getc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2d(%rbp)
jle    11be <exec+0x5e>
movsbl -0x19(%rbp),%eax
cmp    $0x21,%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11ce <exec+0x6e>
jmp    1213 <exec+0xb3>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
jne    11fa <exec+0x9a>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    $0xff,%edi
call   1070 <exit@plt>
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1194 <exec+0x34>
mov    -0x28(%rbp),%rdi
call   1040 <shelly@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
mov    %r15,%rdi
call   1080 <getc@plt>
test   %al,%al
jle    11bc <exec+0x5c>
cmp    $0x21,%al
je     11bc <exec+0x5c>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
cmp    %rbp,%r14
je     11db <exec+0x7b>
mov    %al,(%rbx,%rbp,1)
mov    %r15,%rdi
call   1080 <getc@plt>
test   %al,%al
jle    11bc <exec+0x5c>
add    $0x1,%rbp
cmp    $0x21,%al
jne    11a0 <exec+0x40>
mov    %rbx,%rdi
call   1040 <shelly@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
define i32 @exec(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
%9 = load i64, i64* %4
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %5
%12 = load i8*, i8** %5
store i8* %12, i8** %7
%13 = load i8*, i8** %5
%14 = load i64, i64* %4
%15 = call i32 @memset(i8* %13, i32 0, i64 %14)
br label %16
16: ; preds = %35, %2
%17 = load i32*, i32** %3
%18 = call signext i8 @getc(i32* %17)
store i8 %18, i8* %6
%19 = sext i8 %18 to i32
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 33
br label %25
25: ; preds = %21, %16
%26 = phi i1 [ false, %16 ], [ %24, %21 ]
br i1 %26, label %27, label %39
27: ; preds = %25
%28 = load i64, i64* %4
%29 = add i64 %28, -1
store i64 %29, i64* %4
%30 = icmp ne i64 %28, 0
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = load i8*, i8** %7
%33 = call i32 @free(i8* %32)
%34 = call i32 @exit(i32 255)
unreachable
35: ; preds = %27
%36 = load i8, i8* %6
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %5
store i8 %36, i8* %37
br label %16
39: ; preds = %25
%40 = load i8*, i8** %7
%41 = call i32 @shelly(i8* %40)
store i32 %41, i32* %8
%42 = load i8*, i8** %7
%43 = call i32 @free(i8* %42)
%44 = load i32, i32* %8
ret i32 %44
}

LLVM IR (-O2):
define i32 @exec(i32* nocapture %0, i64 %1) {
%3 = tail call i64 @malloc(i64 %1)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @memset(i8* %4, i32 0, i64 %1)
%6 = tail call signext i8 @getc(i32* %0)
%7 = icmp sgt i8 %6, 0
%8 = icmp ne i8 %6, 33
%9 = and i1 %7, %8
br i1 %9, label %10, label %25
10: ; preds = %2, %18
%11 = phi i8 [ %21, %18 ], [ %6, %2 ]
%12 = phi i64 [ %19, %18 ], [ %1, %2 ]
%13 = phi i8* [ %20, %18 ], [ %4, %2 ]
%14 = icmp eq i64 %12, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @free(i8* %4)
%17 = tail call i32 @exit(i32 255)
unreachable
18: ; preds = %10
%19 = add i64 %12, -1
%20 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %11, i8* %13
%21 = tail call signext i8 @getc(i32* %0)
%22 = icmp sgt i8 %21, 0
%23 = icmp ne i8 %21, 33
%24 = and i1 %22, %23
br i1 %24, label %10, label %25
25: ; preds = %18, %2
%26 = tail call i32 @shelly(i8* %4)
%27 = tail call i32 @free(i8* %4)
ret i32 %26
}