#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 *);
void handle(char *p1, char *p2) {
  int i = 0;
  while (*p1) {
    if (i < 5 - 1) {
      i++;
    } else {
      *p2 = *p1;
      p2++;
    }
    p1++;
  }
  if (5 - 1 > i) {
    printf("The string is too long.");
  } else {
    *p1 = '\0';
  }
}


x86 assembly (clang, -O0):
<handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1175 <handle+0x65>
cmpl   $0x4,-0x14(%rbp)
jge    114c <handle+0x3c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <handle+0x54>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1127 <handle+0x17>
mov    $0x4,%eax
cmp    -0x14(%rbp),%eax
jle    1194 <handle+0x84>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
jmp    119b <handle+0x8b>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle>:
mov    (%rdi),%cl
test   %cl,%cl
je     1140 <handle+0x30>
add    $0x1,%rdi
xor    %eax,%eax
jmp    1131 <handle+0x21>
xchg   %ax,%ax
mov    %cl,(%rsi)
add    $0x1,%rsi
movzbl (%rdi),%ecx
add    $0x1,%rdi
test   %cl,%cl
je     113b <handle+0x2b>
cmp    $0x3,%eax
jg     1120 <handle+0x10>
add    $0x1,%eax
jmp    1126 <handle+0x16>
cmp    $0x3,%eax
jg     114c <handle+0x3c>
lea    0xeb9(%rip),%rdi
jmp    1030 <printf@plt>
movb   $0x0,-0x1(%rdi)
ret

LLVM IR (-O0):
@.str = [24 x i8] c"The string is too long.\00"
define void @handle(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %6
6: ; preds = %22, %2
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %6
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
br label %22
16: ; preds = %10
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = load i8*, i8** %4
store i8 %18, i8* %19
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
br label %22
22: ; preds = %16, %13
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
br label %6
25: ; preds = %6
%26 = load i32, i32* %5
%27 = icmp sgt i32 4, %26
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %32
30: ; preds = %25
%31 = load i8*, i8** %3
store i8 0, i8* %31
br label %32
32: ; preds = %30, %28
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"The string is too long.\00"
define void @handle(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %2, %15
%6 = phi i8 [ %19, %15 ], [ %3, %2 ]
%7 = phi i32 [ %17, %15 ], [ 0, %2 ]
%8 = phi i8* [ %16, %15 ], [ %1, %2 ]
%9 = phi i8* [ %18, %15 ], [ %0, %2 ]
%10 = icmp slt i32 %7, 4
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = add nsw i32 %7, 1
br label %15
13: ; preds = %5
store i8 %6, i8* %8
%14 = getelementptr inbounds i8, i8* %8, i64 1
br label %15
15: ; preds = %13, %11
%16 = phi i8* [ %8, %11 ], [ %14, %13 ]
%17 = phi i32 [ %12, %11 ], [ %7, %13 ]
%18 = getelementptr inbounds i8, i8* %9, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %5
21: ; preds = %15
%22 = icmp slt i32 %17, 4
br i1 %22, label %23, label %25
23: ; preds = %2, %21
%24 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %26
25: ; preds = %21
store i8 0, i8* %18
br label %26
26: ; preds = %25, %23
ret void
}