#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
char *strstr(char *, char *);
int main(int argc, char *argv[]) {
  int count = 0;
  char *ptr;
  if (argc < 3) {
    printf("Please enter two strings.\n");
    return EXIT_FAILURE;
  }
  printf("argv[1] = %s, strlen = %d\n", argv[1], (int)strlen(argv[1]));
  printf("argv[2] = %s, strlen = %d\n", argv[2], (int)strlen(argv[2]));
  ptr = argv[1];
  do {
    ptr = strstr(ptr, argv[2]);
    if (ptr != NULL) {
      printf("%s\n", ptr);
      count++;
      ptr++;
    }
  } while (ptr != NULL);
  if (count == 0) {
    printf("argv[2] is not a substring of argv[1].\n");
  } else {
    printf("argv[2] occurs %d times in argv[1].\n", count);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1176 <main+0x46>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    126d <main+0x13d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1223 <main+0xf3>
mov    -0x20(%rbp),%rsi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1228 <main+0xf8>
cmpq   $0x0,-0x20(%rbp)
jne    11dc <main+0xac>
cmpl   $0x0,-0x14(%rbp)
jne    1250 <main+0x120>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1261 <main+0x131>
mov    -0x14(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jg     1161 <main+0x21>
lea    0xf32(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e84(%rip),%rax
jmp    1208 <main+0xc8>
mov    %rsi,%r14
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe89(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r14),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0xe83(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r14),%rdi
mov    0x10(%r14),%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     11f5 <main+0xb5>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <puts@plt>
add    $0x1,%ebp
add    $0x1,%rbx
mov    0x10(%r14),%rsi
mov    %rbx,%rdi
call   1060 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c0 <main+0x80>
lea    0xe4c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1201 <main+0xc1>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Please enter two strings.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [27 x i8] c"argv[1] = %s, strlen = %d\0A\00"
@.str.2 = [27 x i8] c"argv[2] = %s, strlen = %d\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [40 x i8] c"argv[2] is not a substring of argv[1].\0A\00"
@.str.5 = [37 x i8] c"argv[2] occurs %d times in argv[1].\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
store i32 %12, i32* %3
br label %64
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strlen(i8* %19)
%21 = trunc i64 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 %21)
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i64 @strlen(i8* %28)
%30 = trunc i64 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 %30)
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
store i8* %34, i8** %7
br label %35
35: ; preds = %51, %13
%36 = load i8*, i8** %7
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i8* @strstr(i8* %36, i8* %39)
store i8* %40, i8** %7
%41 = load i8*, i8** %7
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %50
43: ; preds = %35
%44 = load i8*, i8** %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %7
br label %50
50: ; preds = %43, %35
br label %51
51: ; preds = %50
%52 = load i8*, i8** %7
%53 = icmp ne i8* %52, null
br i1 %53, label %35, label %54
54: ; preds = %51
%55 = load i32, i32* %6
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %62
59: ; preds = %54
%60 = load i32, i32* %6
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %59, %57
%63 = load i32, i32* @EXIT_SUCCESS
store i32 %63, i32* %3
br label %64
64: ; preds = %62, %10
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [27 x i8] c"argv[1] = %s, strlen = %d\0A\00"
@.str.2 = [27 x i8] c"argv[2] = %s, strlen = %d\0A\00"
@.str.5 = [37 x i8] c"argv[2] occurs %d times in argv[1].\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [39 x i8] c"argv[2] is not a substring of argv[1].\00"
@str.6 = [26 x i8] c"Please enter two strings.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
br label %34
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%10 = trunc i64 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%15 = trunc i64 %14 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %13, i32 %15)
%17 = load i8*, i8** %7
%18 = load i8*, i8** %12
%19 = tail call i8* @strstr(i8* dereferenceable(1) %17, i8* dereferenceable(1) %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %30, label %21
21: ; preds = %6, %21
%22 = phi i8* [ %28, %21 ], [ %19, %6 ]
%23 = phi i32 [ %25, %21 ], [ 0, %6 ]
%24 = tail call i32 @puts(i8* %22)
%25 = add nuw nsw i32 %23, 1
%26 = getelementptr inbounds i8, i8* %22, i64 1
%27 = load i8*, i8** %12
%28 = tail call i8* @strstr(i8* dereferenceable(1) %26, i8* dereferenceable(1) %27)
%29 = icmp eq i8* %28, null
br i1 %29, label %32, label %21
30: ; preds = %6
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %34
32: ; preds = %21
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i32 %25)
br label %34
34: ; preds = %30, %32, %4
%35 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_SUCCESS, %32 ], [ @EXIT_SUCCESS, %30 ]
%36 = load i32, i32* %35
ret i32 %36
}