#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 *);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int side;
  printf("Perimiter of square: ");
  scanf("%d", &side);
  int i, j, k;
  for (i = 0; i < side; i++) {
    if (i == 0 || i == side - 1) {
      for (j = 0; j < side - 1; j++) {
        printf("X");
      }
      printf("X\n");
    } else {
      for (k = 0; k < side - 1; k++) {
        if (k == 0)
          printf("X");
        else
          printf(" ");
      }
      printf("X\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122d <main+0x10d>
cmpl   $0x0,-0xc(%rbp)
je     1179 <main+0x59>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11bc <main+0x9c>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ab <main+0x8b>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1180 <main+0x60>
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
jmp    121a <main+0xfa>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    120e <main+0xee>
cmpl   $0x0,-0x14(%rbp)
jne    11ef <main+0xcf>
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
jmp    11fb <main+0xdb>
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
jmp    1200 <main+0xe0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c3 <main+0xa3>
lea    0xe06(%rip),%rdi
call   1030 <printf@plt>
jmp    121f <main+0xff>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1152 <main+0x32>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1050 <printf@plt>
lea    0xebb(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    120d <main+0xcd>
xor    %ebp,%ebp
lea    0xe9f(%rip),%r14
jmp    1193 <main+0x53>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <puts@plt>
add    $0x1,%ebp
mov    0xc(%rsp),%eax
cmp    %eax,%ebp
jge    120d <main+0xcd>
test   %ebp,%ebp
je     11e0 <main+0xa0>
lea    -0x1(%rax),%ecx
cmp    %ecx,%ebp
je     11e0 <main+0xa0>
cmp    $0x2,%eax
jl     1180 <main+0x40>
mov    $0x58,%edi
call   1030 <putchar@plt>
cmpl   $0x3,0xc(%rsp)
jl     1180 <main+0x40>
mov    $0x1,%ebx
nopl   0x0(%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%eax
add    $0x1,%ebx
add    $0xffffffff,%eax
cmp    %eax,%ebx
jl     11c0 <main+0x80>
jmp    1180 <main+0x40>
nopw   0x0(%rax,%rax,1)
cmp    $0x2,%eax
jl     1180 <main+0x40>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x58,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    %eax,%ebx
jl     11f0 <main+0xb0>
jmp    1180 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Perimiter of square: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"X\00"
@.str.3 = [3 x i8] c"X\0A\00"
@.str.4 = [2 x i8] c" \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %8
8: ; preds = %53, %0
%9 = load i32, i32* %3
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %56
12: ; preds = %8
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = sub nsw i32 %17, 1
%19 = icmp eq i32 %16, %18
br i1 %19, label %20, label %33
20: ; preds = %15, %12
store i32 0, i32* %4
br label %21
21: ; preds = %28, %20
%22 = load i32, i32* %4
%23 = load i32, i32* %2
%24 = sub nsw i32 %23, 1
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %21
31: ; preds = %21
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %52
33: ; preds = %15
store i32 0, i32* %5
br label %34
34: ; preds = %47, %33
%35 = load i32, i32* %5
%36 = load i32, i32* %2
%37 = sub nsw i32 %36, 1
%38 = icmp slt i32 %35, %37
br i1 %38, label %39, label %50
39: ; preds = %34
%40 = load i32, i32* %5
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %46
44: ; preds = %39
%45 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %44, %42
br label %47
47: ; preds = %46
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %34
50: ; preds = %34
%51 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %50, %31
br label %53
53: ; preds = %52
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
br label %8
56: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Perimiter of square: \00"
@.str.1 = [3 x i8] c"%d\00"
@str.5 = [2 x i8] c"X\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %41
7: ; preds = %0, %35
%8 = phi i32 [ %39, %35 ], [ %5, %0 ]
%9 = phi i32 [ %38, %35 ], [ 0, %0 ]
%10 = icmp eq i32 %9, 0
%11 = add nsw i32 %8, -1
%12 = icmp eq i32 %9, %11
%13 = select i1 %10, i1 true, i1 %12
%14 = icmp sgt i32 %8, 1
br i1 %13, label %20, label %15
15: ; preds = %7
br i1 %14, label %16, label %35
16: ; preds = %15
%17 = call i32 @putchar(i32 88)
%18 = load i32, i32* %1
%19 = icmp sgt i32 %18, 2
br i1 %19, label %28, label %35
20: ; preds = %7
br i1 %14, label %21, label %35
21: ; preds = %20, %21
%22 = phi i32 [ %24, %21 ], [ 0, %20 ]
%23 = call i32 @putchar(i32 88)
%24 = add nuw nsw i32 %22, 1
%25 = load i32, i32* %1
%26 = add nsw i32 %25, -1
%27 = icmp slt i32 %24, %26
br i1 %27, label %21, label %35
28: ; preds = %16, %28
%29 = phi i32 [ %32, %28 ], [ 1, %16 ]
%30 = call i32 @putchar(i32 32)
%31 = load i32, i32* %1
%32 = add nuw nsw i32 %29, 1
%33 = add nsw i32 %31, -1
%34 = icmp slt i32 %32, %33
br i1 %34, label %28, label %35
35: ; preds = %28, %21, %15, %16, %20
%36 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0), %20 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0), %16 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0), %15 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0), %21 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0), %28 ]
%37 = call i32 @puts(i8* dereferenceable(1) %36)
%38 = add nuw nsw i32 %9, 1
%39 = load i32, i32* %1
%40 = icmp slt i32 %38, %39
br i1 %40, label %7, label %41
41: ; preds = %35, %0
ret i32 0
}