#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*/ buf;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
size_t strlen(char *);
int main() {
  char buf[8];
  buf[0] = 'a';
  buf[1] = 'a';
  buf[2] = 'a';
  buf[3] = 'a';
  buf[4] = 'a';
  buf[5] = 'a';
  buf[6] = 'a';
  buf[7] = 'a';
  size_t len = strlen(buf);
  if (fgets(buf, sizeof(buf), stdin)) {
    if (len != 0 && buf[len - 1] == '\n') {
      printf("The non truncated user input %s\n", buf);
    } else {
      printf("Second last character is %d or %c\n", buf[len - 1], buf[len - 1]);
      printf("The truncated user input %s\n", buf);
    }
  } else {
    printf("Error getting data from the user\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x61,-0xc(%rbp)
movb   $0x61,-0xb(%rbp)
movb   $0x61,-0xa(%rbp)
movb   $0x61,-0x9(%rbp)
movb   $0x61,-0x8(%rbp)
movb   $0x61,-0x7(%rbp)
movb   $0x61,-0x6(%rbp)
movb   $0x61,-0x5(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
lea    -0xc(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1204 <main+0xd4>
cmpq   $0x0,-0x18(%rbp)
je     11c5 <main+0x95>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
movsbl -0xc(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11c5 <main+0x95>
lea    -0xc(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ff <main+0xcf>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
movsbl -0xc(%rbp,%rax,1),%esi
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
movsbl -0xc(%rbp,%rax,1),%edx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1212 <main+0xe2>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
movabs $0x6161616161616161,%rax
61 61 61
mov    %rax,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x8,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1192 <main+0x52>
test   %rbx,%rbx
je     11a0 <main+0x60>
mov    -0x1(%rbx,%r14,1),%al
cmp    $0xa,%al
jne    11a4 <main+0x64>
lea    0xe70(%rip),%rdi
jmp    11be <main+0x7e>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
jmp    11c8 <main+0x88>
mov    -0x1(%rsp),%al
movsbl %al,%edx
lea    0xe73(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe86(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [33 x i8] c"The non truncated user input %s\0A\00"
@.str.1 = [35 x i8] c"Second last character is %d or %c\0A\00"
@.str.2 = [29 x i8] c"The truncated user input %s\0A\00"
@.str.3 = [34 x i8] c"Error getting data from the user\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca i64
store i32 0, i32* %1
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
store i8 97, i8* %4
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 1
store i8 97, i8* %5
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 2
store i8 97, i8* %6
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 3
store i8 97, i8* %7
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 4
store i8 97, i8* %8
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 5
store i8 97, i8* %9
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 6
store i8 97, i8* %10
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 7
store i8 97, i8* %11
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %3
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i64 @fgets(i8* %14, i32 8, i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %46
18: ; preds = %0
%19 = load i64, i64* %3
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i64, i64* %3
%23 = sub i64 %22, 1
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %45
31: ; preds = %21, %18
%32 = load i64, i64* %3
%33 = sub i64 %32, 1
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = load i64, i64* %3
%38 = sub i64 %37, 1
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 %41)
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %31, %28
br label %48
46: ; preds = %0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %45
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [33 x i8] c"The non truncated user input %s\0A\00"
@.str.1 = [35 x i8] c"Second last character is %d or %c\0A\00"
@.str.2 = [29 x i8] c"The truncated user input %s\0A\00"
@str = [33 x i8] c"Error getting data from the user\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to [8 x i8]*
%3 = bitcast i64* %1 to i8*
store i64 7016996765293437281, i64* %1
%4 = call i64 @strlen(i8* %3)
%5 = load i32, i32* @stdin
%6 = call i64 @fgets(i8* %3, i32 8, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %0
%9 = icmp eq i64 %4, 0
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 -1
%12 = load i8, i8* %11
br label %20
13: ; preds = %8
%14 = add i64 %4, -1
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 10
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64* %1)
br label %27
20: ; preds = %10, %13
%21 = phi i8 [ %12, %10 ], [ %16, %13 ]
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64* %1)
br label %27
25: ; preds = %0
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %18, %20, %25
ret i32 0
}