#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 echo0(char *, size_t);
scalar_t__ memcmp(char *, char *, int);
int nanosleep0(char *, size_t);
int open0(char *, size_t);
int do_line(char *s, size_t length) {
  if (length == 0)
    return 0;
  if (length >= 5 && memcmp(s, "echo ", 5) == 0) {
    return echo0(s + 5, length - 5);
  }
  if (length >= 5 && memcmp(s, "open ", 5) == 0) {
    return open0(s + 5, length - 5);
  }
  if (length >= 10 && memcmp(s, "nanosleep ", 10) == 0) {
    return nanosleep0(s + 10, length - 10);
  }
  return -1;
}


x86 assembly (clang, -O0):
<do_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1167 <do_line+0x27>
movl   $0x0,-0x4(%rbp)
jmp    1243 <do_line+0x103>
cmpq   $0x5,-0x18(%rbp)
jb     11ae <do_line+0x6e>
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11ae <do_line+0x6e>
mov    -0x10(%rbp),%rdi
add    $0x5,%rdi
mov    -0x18(%rbp),%rsi
sub    $0x5,%rsi
call   1050 <echo0@plt>
mov    %eax,-0x4(%rbp)
jmp    1243 <do_line+0x103>
cmpq   $0x5,-0x18(%rbp)
jb     11f5 <do_line+0xb5>
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    11f5 <do_line+0xb5>
mov    -0x10(%rbp),%rdi
add    $0x5,%rdi
mov    -0x18(%rbp),%rsi
sub    $0x5,%rsi
call   1030 <open0@plt>
mov    %eax,-0x4(%rbp)
jmp    1243 <do_line+0x103>
cmpq   $0xa,-0x18(%rbp)
jb     123c <do_line+0xfc>
mov    -0x10(%rbp),%rdi
lea    0xe01(%rip),%rsi
mov    $0xa,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    123c <do_line+0xfc>
mov    -0x10(%rbp),%rdi
add    $0xa,%rdi
mov    -0x18(%rbp),%rsi
sub    $0xa,%rsi
call   1060 <nanosleep0@plt>
mov    %eax,-0x4(%rbp)
jmp    1243 <do_line+0x103>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_line>:
push   %rbp
push   %r14
push   %rbx
test   %rsi,%rsi
je     11bf <do_line+0x7f>
mov    %rsi,%rbx
mov    $0xffffffff,%ebp
cmp    $0x5,%rsi
jb     11c1 <do_line+0x81>
mov    %rdi,%r14
lea    0xe9f(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     11c8 <do_line+0x88>
lea    0xe8f(%rip),%rsi
mov    %r14,%rdi
mov    $0x5,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     11df <do_line+0x9f>
cmp    $0xa,%rbx
jb     11c1 <do_line+0x81>
lea    0xe76(%rip),%rsi
mov    %r14,%rdi
mov    $0xa,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    11c1 <do_line+0x81>
add    $0xa,%r14
add    $0xfffffffffffffff6,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <nanosleep0@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
add    $0x5,%r14
add    $0xfffffffffffffffb,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <echo0@plt>
add    $0x5,%r14
add    $0xfffffffffffffffb,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <open0@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"echo \00"
@.str.1 = [6 x i8] c"open \00"
@.str.2 = [11 x i8] c"nanosleep \00"
define i32 @do_line(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%6 = load i64, i64* %5
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 0, i32* %3
br label %49
9: ; preds = %2
%10 = load i64, i64* %5
%11 = icmp uge i64 %10, 5
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i8*, i8** %4
%14 = call i64 @memcmp(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 5
%19 = load i64, i64* %5
%20 = sub i64 %19, 5
%21 = call i32 @echo0(i8* %18, i64 %20)
store i32 %21, i32* %3
br label %49
22: ; preds = %12, %9
%23 = load i64, i64* %5
%24 = icmp uge i64 %23, 5
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i8*, i8** %4
%27 = call i64 @memcmp(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 5
%32 = load i64, i64* %5
%33 = sub i64 %32, 5
%34 = call i32 @open0(i8* %31, i64 %33)
store i32 %34, i32* %3
br label %49
35: ; preds = %25, %22
%36 = load i64, i64* %5
%37 = icmp uge i64 %36, 10
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load i8*, i8** %4
%40 = call i64 @memcmp(i8* %39, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i64 10
%45 = load i64, i64* %5
%46 = sub i64 %45, 10
%47 = call i32 @nanosleep0(i8* %44, i64 %46)
store i32 %47, i32* %3
br label %49
48: ; preds = %38, %35
store i32 -1, i32* %3
br label %49
49: ; preds = %48, %42, %29, %16, %8
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [6 x i8] c"echo \00"
@.str.1 = [6 x i8] c"open \00"
@.str.2 = [11 x i8] c"nanosleep \00"
define i32 @do_line(i8* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %29, label %4
4: ; preds = %2
%5 = icmp ugt i64 %1, 4
br i1 %5, label %6, label %29
6: ; preds = %4
%7 = tail call i64 @memcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %0, i64 5
%11 = add i64 %1, -5
%12 = tail call i32 @echo0(i8* %10, i64 %11)
br label %29
13: ; preds = %6
%14 = tail call i64 @memcmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %0, i64 5
%18 = add i64 %1, -5
%19 = tail call i32 @open0(i8* %17, i64 %18)
br label %29
20: ; preds = %13
%21 = icmp ugt i64 %1, 9
br i1 %21, label %22, label %29
22: ; preds = %20
%23 = tail call i64 @memcmp(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 10)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = getelementptr inbounds i8, i8* %0, i64 10
%27 = add i64 %1, -10
%28 = tail call i32 @nanosleep0(i8* %26, i64 %27)
br label %29
29: ; preds = %4, %20, %22, %2, %25, %16, %9
%30 = phi i32 [ %12, %9 ], [ %19, %16 ], [ %28, %25 ], [ 0, %2 ], [ -1, %22 ], [ -1, %20 ], [ -1, %4 ]
ret i32 %30
}