#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*/ SIGINT;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, void (*)(int));
scalar_t__ strncmp(char *, char *, int);
int main() {
  void inthander(int);
  void quithander(int);
  char input[100];
  int nchars;
  signal(SIGINT, inthander);
  signal(SIGQUIT, quithander);
  do {
    printf("\nType a message:\n");
    nchars = read(0, input, 100 - 1);
    if (nchars == -1)
      perror("read return an error");
    else {
      input[nchars] = '\0';
      printf("You typed: %s\n", input);
    }
  } while (strncmp(input, "quit", 4) != 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    0x2e56(%rip),%rsi
call   1060 <signal@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rsi
call   1060 <signal@plt>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rsi
xor    %edi,%edi
mov    $0x63,%edx
call   1050 <read@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0xffffffff,-0x74(%rbp)
jne    11c8 <main+0x78>
lea    0xe54(%rip),%rdi
call   1070 <perror@plt>
jmp    11e3 <main+0x93>
movslq -0x74(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e8 <main+0x98>
lea    -0x70(%rbp),%rdi
lea    0xe43(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    118c <main+0x3c>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    0x2e4b(%rip),%rsi
call   1070 <signal@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e4e(%rip),%rsi
call   1070 <signal@plt>
lea    0xe8b(%rip),%r14
mov    %rsp,%rbx
lea    0xe58(%rip),%r15
lea    0xe75(%rip),%r12
lea    0xe5f(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x63,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     1206 <main+0xa6>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
jmp    1210 <main+0xb0>
mov    %r15,%rdi
call   1080 <perror@plt>
jmp    11ef <main+0x8f>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SIGINT = global i32 0
@SIGQUIT = global i32 0
@.str = [18 x i8] c"\0AType a message:\0A\00"
@.str.1 = [21 x i8] c"read return an error\00"
@.str.2 = [15 x i8] c"You typed: %s\0A\00"
@.str.3 = [5 x i8] c"quit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @SIGINT
%5 = call i32 @signal(i32 %4, void (i32)* @inthander)
%6 = load i32, i32* @SIGQUIT
%7 = call i32 @signal(i32 %6, void (i32)* @quithander)
br label %8
8: ; preds = %23, %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%11 = call i32 @read(i32 0, i8* %10, i32 99)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %22
16: ; preds = %8
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %16, %14
br label %23
23: ; preds = %22
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%25 = call i64 @strncmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%26 = icmp ne i64 %25, 0
br i1 %26, label %8, label %27
27: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIGQUIT = global i32 0
@.str.1 = [21 x i8] c"read return an error\00"
@.str.2 = [15 x i8] c"You typed: %s\0A\00"
@.str.3 = [5 x i8] c"quit\00"
@str = [17 x i8] c"\0AType a message:\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @SIGINT
%4 = tail call i32 @signal(i32 %3, void (i32)* @inthander)
%5 = load i32, i32* @SIGQUIT
%6 = tail call i32 @signal(i32 %5, void (i32)* @quithander)
br label %7
7: ; preds = %17, %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%9 = call i32 @read(i32 0, i8* %2, i32 99)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %17
13: ; preds = %7
%14 = sext i32 %9 to i64
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %17
17: ; preds = %11, %13
%18 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %7
20: ; preds = %17
ret i32 0
}