#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*/ mystrcat(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char s1[] = "blahBLAHblah";
  char s2[1000];
  char *s2p = &s2[0];
  int i, j;
  for (j = 0; s1[j] != '\0'; j++)
    ;
  for (i = 0; i < 4; i++) {
    mystrcat(s2p + i * j, s1);
  }
  printf("Final s2: %s\n", s2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x11(%rbp)
mov    0xec5(%rip),%eax
mov    %eax,-0x9(%rbp)
mov    0xec0(%rip),%al
mov    %al,-0x5(%rbp)
lea    -0x400(%rbp),%rax
mov    %rax,-0x408(%rbp)
movl   $0x0,-0x410(%rbp)
movslq -0x410(%rbp),%rax
movsbl -0x11(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     1195 <main+0x75>
jmp    1181 <main+0x61>
mov    -0x410(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x410(%rbp)
jmp    1167 <main+0x47>
movl   $0x0,-0x40c(%rbp)
cmpl   $0x4,-0x40c(%rbp)
jge    11e2 <main+0xc2>
mov    -0x408(%rbp),%rdi
mov    -0x40c(%rbp),%eax
imul   -0x410(%rbp),%eax
cltq
add    %rax,%rdi
lea    -0x11(%rbp),%rsi
call   1040 <mystrcat@plt>
mov    -0x40c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40c(%rbp)
jmp    119f <main+0x7f>
lea    -0x400(%rbp),%rsi
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
movabs $0x68616c6248414c,%rax
mov    %rax,0x5(%rsp)
movabs $0x48414c4268616c62,%rax
4c 41 48
mov    %rax,(%rsp)
xor    %r13d,%r13d
xor    %ebx,%ebx
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x3,%r12
add    $0x2,%rbx
cmpb   $0x0,0x1(%rsp,%r13,1)
lea    0x1(%r13),%r13
jne    1160 <main+0x40>
lea    0x10(%rsp),%r14
mov    %rsp,%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <mystrcat@plt>
mov    %r13d,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
mov    %r15,%rsi
call   1040 <mystrcat@plt>
and    $0xfffffffe,%ebx
lea    (%rsp,%rbx,1),%rdi
add    $0x10,%rdi
mov    %r15,%rsi
call   1040 <mystrcat@plt>
mov    %r12d,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
mov    %r15,%rsi
call   1040 <mystrcat@plt>
lea    0xe46(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.s1 = [13 x i8] c"blahBLAHblah\00"
@.str = [14 x i8] c"Final s2: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [13 x i8]
%3 = alloca [1000 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [13 x i8]* %2 to i8*
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
store i8* %8, i8** %4
store i32 0, i32* %6
br label %9
9: ; preds = %17, %0
%10 = load i32, i32* %6
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %9
br label %17
17: ; preds = %16
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
store i32 %19, i32* %6
br label %9
20: ; preds = %9
store i32 0, i32* %5
br label %21
21: ; preds = %33, %20
%22 = load i32, i32* %5
%23 = icmp slt i32 %22, 4
br i1 %23, label %24, label %36
24: ; preds = %21
%25 = load i8*, i8** %4
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = mul nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
%31 = getelementptr inbounds [13 x i8], [13 x i8]* %2, i64 0, i64 0
%32 = call i32 @mystrcat(i8* %30, i8* %31)
br label %33
33: ; preds = %24
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %21
36: ; preds = %21
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%38 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@__const.main.s1 = [13 x i8] c"blahBLAHblah\00"
@.str = [14 x i8] c"Final s2: %s\0A\00"
define i32 @main() {
%1 = alloca [13 x i8]
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %0, %5
%6 = phi i64 [ 1, %0 ], [ %10, %5 ]
%7 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = add nuw i64 %6, 1
br i1 %9, label %11, label %5
11: ; preds = %5
%12 = call i32 @mystrcat(i8* %4, i8* %3)
%13 = and i64 %6, 4294967295
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %13
%15 = call i32 @mystrcat(i8* %14, i8* %3)
%16 = shl i64 %6, 1
%17 = and i64 %16, 4294967294
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %17
%19 = call i32 @mystrcat(i8* %18, i8* %3)
%20 = mul i64 %6, 3
%21 = and i64 %20, 4294967295
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %21
%23 = call i32 @mystrcat(i8* %22, i8* %3)
%24 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %4)
ret i32 0
}