#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 */
typedef int /*<<< orphan*/ string;

/* Variables and functions */
int /*<<< orphan*/ WrMessage(char *);
int /*<<< orphan*/ printf(char *, int *, char *, int *);
int /*<<< orphan*/ strcpy(char *, char *);
void WrStringOverflow(void) {
  int int_before;
  char string[10];
  int int_after;
  long diff1;
  long diff2;
  char second_string[10];
  strcpy(second_string, "Dummy");
  WrMessage("@STRING-OVERFLOW");
  int_before = -1;
  int_after = -1;
  printf("Adresses of the variables:\nint before: %p\nstring:     %p\nint "
         "after:  %p\n",
         &int_before, string, &int_after);
  strcpy(string, "1234567890");
  if (int_before != -1) {
    WrMessage("@STRING-OVERFLOW-BEFORE");
  }
  if (int_after != -1) {
    WrMessage("@STRING-OVERFLOW-AFTER");
  }
  if (int_before == -1 && int_after == -1) {
    WrMessage("@STRING-OVERFLOW-NO-EFFECT");
    diff1 = (long)&int_after - (long)&string[0];
    diff2 = (long)&int_after - (long)&int_before;
    if (diff1 > sizeof(string)) {
      WrMessage("@STRING-OVERFLOW-MEMORY-ALIGNMENT");
    } else {
      if (diff2 > diff1) {
        WrMessage("@STRING-OVERFLOW-STACK-REORGANISED");
      } else {
        WrMessage("@STRING-OVERFLOW-MEMORY-ALIGNMENT");
      }
    }
  }
  return;
}


x86 assembly (clang, -O0):
<WrStringOverflow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x32(%rbp),%rdi
lea    0xebd(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xeb7(%rip),%rdi
call   1050 <WrMessage@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    -0xe(%rbp),%rdx
lea    0xeaa(%rip),%rdi
lea    -0x4(%rbp),%rsi
lea    -0x14(%rbp),%rcx
call   1040 <printf@plt>
lea    -0xe(%rbp),%rdi
lea    0xedb(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0xffffffff,-0x4(%rbp)
je     11a0 <WrStringOverflow+0x70>
lea    0xed0(%rip),%rdi
call   1050 <WrMessage@plt>
cmpl   $0xffffffff,-0x14(%rbp)
je     11b6 <WrStringOverflow+0x86>
lea    0xed2(%rip),%rdi
call   1050 <WrMessage@plt>
cmpl   $0xffffffff,-0x4(%rbp)
jne    1245 <WrStringOverflow+0x115>
cmpl   $0xffffffff,-0x14(%rbp)
jne    1245 <WrStringOverflow+0x115>
lea    0xec9(%rip),%rdi
call   1050 <WrMessage@plt>
lea    -0x14(%rbp),%rax
lea    -0xe(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
lea    -0x14(%rbp),%rax
lea    -0x4(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0xa,-0x20(%rbp)
jbe    1210 <WrStringOverflow+0xe0>
lea    0xeaf(%rip),%rdi
call   1050 <WrMessage@plt>
jmp    1240 <WrStringOverflow+0x110>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    122f <WrStringOverflow+0xff>
lea    0xeb2(%rip),%rdi
call   1050 <WrMessage@plt>
jmp    123b <WrStringOverflow+0x10b>
lea    0xe7f(%rip),%rdi
call   1050 <WrMessage@plt>
jmp    1240 <WrStringOverflow+0x110>
jmp    1245 <WrStringOverflow+0x115>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WrStringOverflow>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xec0(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0xeb5(%rip),%rdi
call   1050 <WrMessage@plt>
movl   $0xffffffff,0x8(%rsp)
ff
movl   $0xffffffff,0x4(%rsp)
ff
lea    0xeaa(%rip),%rdi
lea    0x8(%rsp),%r14
lea    0x16(%rsp),%r15
lea    0x4(%rsp),%rbx
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1040 <printf@plt>
lea    0xecf(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
cmpl   $0xffffffff,0x8(%rsp)
je     11ac <WrStringOverflow+0x7c>
lea    0xec4(%rip),%rdi
call   1050 <WrMessage@plt>
cmpl   $0xffffffff,0x4(%rsp)
je     11d0 <WrStringOverflow+0xa0>
lea    0xec9(%rip),%rdi
call   1050 <WrMessage@plt>
cmpl   $0xffffffff,0x4(%rsp)
sete   %al
cmpl   $0xffffffff,0x8(%rsp)
je     11d9 <WrStringOverflow+0xa9>
jmp    120e <WrStringOverflow+0xde>
mov    $0x1,%al
cmpl   $0xffffffff,0x8(%rsp)
jne    120e <WrStringOverflow+0xde>
test   %al,%al
je     120e <WrStringOverflow+0xde>
lea    0xeb6(%rip),%rdi
call   1050 <WrMessage@plt>
sub    %r15,%rbx
cmp    %r14,%r15
lea    0xee1(%rip),%rdi
lea    0xeb8(%rip),%rax
cmovle %rax,%rdi
cmp    $0xb,%rbx
cmovae %rax,%rdi
call   1050 <WrMessage@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Dummy\00"
@.str.1 = [17 x i8] c"@STRING-OVERFLOW\00"
@.str.2 = [73 x i8] c"Adresses of the variables:\0Aint before: %p\0Astring: %p\0Aint after: %p\0A\00"
@.str.3 = [11 x i8] c"1234567890\00"
@.str.4 = [24 x i8] c"@STRING-OVERFLOW-BEFORE\00"
@.str.5 = [23 x i8] c"@STRING-OVERFLOW-AFTER\00"
@.str.6 = [27 x i8] c"@STRING-OVERFLOW-NO-EFFECT\00"
@.str.7 = [34 x i8] c"@STRING-OVERFLOW-MEMORY-ALIGNMENT\00"
@.str.8 = [35 x i8] c"@STRING-OVERFLOW-STACK-REORGANISED\00"
define void @WrStringOverflow() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca [10 x i8]
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @WrMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
store i32 -1, i32* %3
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%11 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0), i32* %1, i8* %10, i32* %3)
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* %1
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @WrMessage(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %16, %0
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @WrMessage(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = load i32, i32* %1
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %52
26: ; preds = %23
%27 = load i32, i32* %3
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %52
29: ; preds = %26
%30 = call i32 @WrMessage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%31 = ptrtoint i32* %3 to i64
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%33 = ptrtoint i8* %32 to i64
%34 = sub nsw i64 %31, %33
store i64 %34, i64* %4
%35 = ptrtoint i32* %3 to i64
%36 = ptrtoint i32* %1 to i64
%37 = sub nsw i64 %35, %36
store i64 %37, i64* %5
%38 = load i64, i64* %4
%39 = icmp ugt i64 %38, 10
br i1 %39, label %40, label %42
40: ; preds = %29
%41 = call i32 @WrMessage(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
br label %51
42: ; preds = %29
%43 = load i64, i64* %5
%44 = load i64, i64* %4
%45 = icmp sgt i64 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @WrMessage(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
br label %50
48: ; preds = %42
%49 = call i32 @WrMessage(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
br label %51
51: ; preds = %50, %40
br label %52
52: ; preds = %51, %26, %23
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"Dummy\00"
@.str.1 = [17 x i8] c"@STRING-OVERFLOW\00"
@.str.2 = [73 x i8] c"Adresses of the variables:\0Aint before: %p\0Astring: %p\0Aint after: %p\0A\00"
@.str.3 = [11 x i8] c"1234567890\00"
@.str.4 = [24 x i8] c"@STRING-OVERFLOW-BEFORE\00"
@.str.5 = [23 x i8] c"@STRING-OVERFLOW-AFTER\00"
@.str.6 = [27 x i8] c"@STRING-OVERFLOW-NO-EFFECT\00"
@.str.7 = [34 x i8] c"@STRING-OVERFLOW-MEMORY-ALIGNMENT\00"
@.str.8 = [35 x i8] c"@STRING-OVERFLOW-STACK-REORGANISED\00"
define void @WrStringOverflow() {
%1 = alloca i32
%2 = alloca [10 x i8]
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = bitcast i32* %1 to i8*
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @WrMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
store i32 -1, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.2, i64 0, i64 0), i32* %1, i8* %6, i32* %3)
%12 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32, i32* %1
%14 = icmp eq i32 %13, -1
br i1 %14, label %17, label %15
15: ; preds = %0
%16 = call i32 @WrMessage(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %15, %0
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, -1
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = call i32 @WrMessage(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, -1
br label %24
24: ; preds = %20, %17
%25 = phi i1 [ %23, %20 ], [ true, %17 ]
%26 = load i32, i32* %1
%27 = icmp eq i32 %26, -1
%28 = select i1 %27, i1 %25, i1 false
br i1 %28, label %29, label %40
29: ; preds = %24
%30 = call i32 @WrMessage(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%31 = ptrtoint i32* %3 to i64
%32 = ptrtoint [10 x i8]* %2 to i64
%33 = sub nsw i64 %31, %32
%34 = icmp ugt i64 %33, 10
%35 = bitcast i32* %1 to [10 x i8]*
%36 = icmp sgt [10 x i8]* %2, %35
%37 = select i1 %36, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0)
%38 = select i1 %34, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), i8* %37
%39 = call i32 @WrMessage(i8* %38)
br label %40
40: ; preds = %29, %24
ret void
}