#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 check_cat(char *, int, int);
int check_copy(char *, int, int);
int strlen(char *);
int /*<<< orphan*/ test_strconcat();
int /*<<< orphan*/ test_strfmt();
int str_main(void) {
  int rc = 0;
  int len = strlen("hello world");
  for (int i = 0; i < len + 2; ++i) {
    rc |= check_copy("hello world", i, i);
    rc |= check_cat("hello world", i + 5, i);
  }
  test_strconcat();
  test_strfmt();
  return rc;
}


x86 assembly (clang, -O0):
<str_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    11c7 <str_main+0x77>
mov    -0xc(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe6d(%rip),%rdi
call   1050 <check_copy@plt>
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%esi
add    $0x5,%esi
mov    -0xc(%rbp),%edx
lea    0xe52(%rip),%rdi
call   1030 <check_cat@plt>
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1175 <str_main+0x25>
mov    $0x0,%al
call   1060 <test_strconcat@plt>
mov    $0x0,%al
call   1070 <test_strfmt@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xea1(%rip),%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
jl     11ae <str_main+0x5e>
mov    %eax,%r15d
add    $0x1,%r15d
xor    %ebx,%ebx
lea    0xe85(%rip),%r14
xor    %ebp,%ebp
nopl   (%rax)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebx,%edx
call   1050 <check_copy@plt>
mov    %eax,%r12d
or     %ebp,%r12d
lea    0x5(%rbx),%esi
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <check_cat@plt>
mov    %eax,%ebp
or     %r12d,%ebp
lea    0x1(%rbx),%eax
cmp    %r15d,%ebx
mov    %eax,%ebx
jne    1180 <str_main+0x30>
xor    %eax,%eax
call   1060 <test_strconcat@plt>
xor    %eax,%eax
call   1070 <test_strfmt@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"hello world\00"
define i32 @str_main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %4, i32* %2
store i32 0, i32* %3
br label %5
5: ; preds = %22, %0
%6 = load i32, i32* %3
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 2
%9 = icmp slt i32 %6, %8
br i1 %9, label %10, label %25
10: ; preds = %5
%11 = load i32, i32* %3
%12 = load i32, i32* %3
%13 = call i32 @check_copy(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = load i32, i32* %1
%15 = or i32 %14, %13
store i32 %15, i32* %1
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 5
%18 = load i32, i32* %3
%19 = call i32 @check_cat(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18)
%20 = load i32, i32* %1
%21 = or i32 %20, %19
store i32 %21, i32* %1
br label %22
22: ; preds = %10
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %5
25: ; preds = %5
%26 = call i32 (...) @test_strconcat()
%27 = call i32 (...) @test_strfmt()
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [12 x i8] c"hello world\00"
define i32 @str_main() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%2 = icmp sgt i32 %1, -2
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = add i32 %1, 1
br label %9
5: ; preds = %9, %0
%6 = phi i32 [ 0, %0 ], [ %16, %9 ]
%7 = tail call i32 (...) @test_strconcat()
%8 = tail call i32 (...) @test_strfmt()
ret i32 %6
9: ; preds = %3, %9
%10 = phi i32 [ %17, %9 ], [ 0, %3 ]
%11 = phi i32 [ %16, %9 ], [ 0, %3 ]
%12 = tail call i32 @check_copy(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %10)
%13 = or i32 %12, %11
%14 = add nuw nsw i32 %10, 5
%15 = tail call i32 @check_cat(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %10)
%16 = or i32 %13, %15
%17 = add nuw i32 %10, 1
%18 = icmp eq i32 %10, %4
br i1 %18, label %5, label %9
}