#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 cmd_ichar(char *, int);
int /*<<< orphan*/ ring_bell();
int /*<<< orphan*/ step_char(char **, int, char *);
int strlen(char *);
int cmd_istr(char *str) {
  char *s;
  int action;
  char *endline = str + strlen(str);
  for (s = str; *s != '\0';) {
    char *os = s;
    step_char(&s, +1, endline);
    action = cmd_ichar(os, s - os);
    if (action != 0) {
      ring_bell();
      return (action);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<cmd_istr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d9 <cmd_istr+0x99>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1050 <step_char@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1030 <cmd_ichar@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d4 <cmd_istr+0x94>
mov    $0x0,%al
call   1060 <ring_bell@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e0 <cmd_istr+0xa0>
jmp    1175 <cmd_istr+0x35>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_istr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rbx,(%rsp)
xor    %r14d,%r14d
cmpb   $0x0,(%rbx)
je     11a8 <cmd_istr+0x68>
movslq %eax,%rbp
add    %rbx,%rbp
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
call   1050 <step_char@plt>
mov    (%rsp),%esi
sub    %ebx,%esi
mov    %rbx,%rdi
call   1030 <cmd_ichar@plt>
test   %eax,%eax
jne    119c <cmd_istr+0x5c>
mov    (%rsp),%rbx
cmpb   $0x0,(%rbx)
jne    1170 <cmd_istr+0x30>
jmp    11a8 <cmd_istr+0x68>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <ring_bell@plt>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cmd_istr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
store i8* %12, i8** %6
%13 = load i8*, i8** %3
store i8* %13, i8** %4
br label %14
14: ; preds = %36, %1
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %14
%20 = load i8*, i8** %4
store i8* %20, i8** %7
%21 = load i8*, i8** %6
%22 = call i32 @step_char(i8** %4, i32 1, i8* %21)
%23 = load i8*, i8** %7
%24 = load i8*, i8** %4
%25 = load i8*, i8** %7
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
%30 = call i32 @cmd_ichar(i8* %23, i32 %29)
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %19
%34 = call i32 (...) @ring_bell()
%35 = load i32, i32* %5
store i32 %35, i32* %2
br label %38
36: ; preds = %19
br label %14
37: ; preds = %14
store i32 0, i32* %2
br label %38
38: ; preds = %37, %33
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
define i32 @cmd_istr(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
store i8* %0, i8** %2
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %1, %19
%10 = phi i8* [ %20, %19 ], [ %0, %1 ]
%11 = call i32 @step_char(i8** %2, i32 1, i8* %6)
%12 = load i8*, i8** %2
%13 = ptrtoint i8* %12 to i64
%14 = ptrtoint i8* %10 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = call i32 @cmd_ichar(i8* %10, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %9
%20 = load i8*, i8** %2
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %25, label %9
23: ; preds = %9
%24 = call i32 (...) @ring_bell()
br label %25
25: ; preds = %19, %1, %23
%26 = phi i32 [ %17, %23 ], [ 0, %1 ], [ 0, %19 ]
ret i32 %26
}