#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 main(int argc, char *argv[]) {
  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):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe8c(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    11d5 <main+0x85>
mov    -0x1c(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe5f(%rip),%rdi
call   1050 <check_copy@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%esi
add    $0x5,%esi
mov    -0x1c(%rbp),%edx
lea    0xe44(%rip),%rdi
call   1030 <check_cat@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1183 <main+0x33>
mov    $0x0,%al
call   1060 <test_strconcat@plt>
mov    $0x0,%al
call   1070 <test_strfmt@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<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 <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 <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 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %9, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %27, %2
%11 = load i32, i32* %8
%12 = load i32, i32* %7
%13 = add nsw i32 %12, 2
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %30
15: ; preds = %10
%16 = load i32, i32* %8
%17 = load i32, i32* %8
%18 = call i32 @check_copy(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
%19 = load i32, i32* %6
%20 = or i32 %19, %18
store i32 %20, i32* %6
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 5
%23 = load i32, i32* %8
%24 = call i32 @check_cat(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %23)
%25 = load i32, i32* %6
%26 = or i32 %25, %24
store i32 %26, i32* %6
br label %27
27: ; preds = %15
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %10
30: ; preds = %10
%31 = call i32 (...) @test_strconcat()
%32 = call i32 (...) @test_strfmt()
%33 = load i32, i32* %6
ret i32 %33
}

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