#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*/ printf(char *, int, int);
int strlen(char *);
int count(char containers[], int j, int L) {
  int res = 0;
  while (j < strlen(containers) && L > 0) {
    if (containers[j] == 'X') {
      res++;
    }
    L--;
    j++;
  }
  printf(" for %d containers are %d \n", j, res);
  return res;
}


x86 assembly (clang, -O0):
<count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1c(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x15(%rbp)
jge    1164 <count+0x44>
cmpl   $0x0,-0x10(%rbp)
setg   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1174 <count+0x54>
jmp    11a9 <count+0x89>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x58,%eax
jne    1192 <count+0x72>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <count+0x19>
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %esi,%r15d
mov    %rdi,%r14
call   1030 <strlen@plt>
xor    %ebp,%ebp
cmp    %r15d,%eax
jle    1185 <count+0x65>
test   %r12d,%r12d
jle    1185 <count+0x65>
movslq %r15d,%rbx
add    $0x1,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
xor    %ebp,%ebp
cmpb   $0x58,-0x1(%r14,%rbx,1)
sete   %bpl
add    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    $0x1,%r15d
cmp    %rax,%rbx
jge    1185 <count+0x65>
lea    -0x1(%r12),%eax
add    $0x1,%rbx
cmp    $0x1,%r12d
mov    %eax,%r12d
ja     1150 <count+0x30>
lea    0xe74(%rip),%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1040 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c" for %d containers are %d \0A\00"
define i32 @count(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %29, %3
%9 = load i32, i32* %5
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* %6
%15 = icmp sgt i32 %14, 0
br label %16
16: ; preds = %13, %8
%17 = phi i1 [ false, %8 ], [ %15, %13 ]
br i1 %17, label %18, label %34
18: ; preds = %16
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 88
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %29
29: ; preds = %26, %18
%30 = load i32, i32* %6
%31 = add nsw i32 %30, -1
store i32 %31, i32* %6
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %8
34: ; preds = %16
%35 = load i32, i32* %5
%36 = load i32, i32* %7
%37 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %36)
%38 = load i32, i32* %7
ret i32 %38
}

LLVM IR (-O2):
@.str = [28 x i8] c" for %d containers are %d \0A\00"
define i32 @count(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, %1
%6 = icmp sgt i32 %2, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %28
8: ; preds = %3
%9 = sext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ %9, %8 ], [ %20, %10 ]
%12 = phi i32 [ 0, %8 ], [ %18, %10 ]
%13 = phi i32 [ %2, %8 ], [ %19, %10 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %11
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 88
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %12, %17
%19 = add nsw i32 %13, -1
%20 = add nsw i64 %11, 1
%21 = tail call i32 @strlen(i8* %0)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
%24 = icmp ugt i32 %13, 1
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %10, label %26
26: ; preds = %10
%27 = trunc i64 %20 to i32
br label %28
28: ; preds = %26, %3
%29 = phi i32 [ %1, %3 ], [ %27, %26 ]
%30 = phi i32 [ 0, %3 ], [ %18, %26 ]
%31 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %30)
ret i32 %30
}