#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__ strcmp(char *, char *, int);
main(int argc, char *argv[]) {
  void inthandler(int);
  void quithandler(int);
  char input[100];
  int nchars;
  signal(SIGINT, inthandler);
  signal(SIGQUIT, quithandler);
  do {
    printf("\nType a message\n");
    nchars = read(0, input, (100 - 1));
    if (nchars == -1)
      perror("read returned an error!\n");
    else {
      input[nchars] = '\0';
      printf("You typed: %s ", input);
    }
  } while (strcmp(input, "quit", 4) != 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    0x2e6f(%rip),%rsi
call   1060 <signal@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    0x2e4a(%rip),%rsi
call   1060 <signal@plt>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x80(%rbp),%rsi
xor    %edi,%edi
mov    $0x63,%edx
call   1040 <read@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xffffffff,-0x84(%rbp)
jne    11d5 <main+0x85>
lea    0xe46(%rip),%rdi
call   1070 <perror@plt>
jmp    11f3 <main+0xa3>
movslq -0x84(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f8 <main+0xa8>
lea    -0x80(%rbp),%rdi
lea    0xe36(%rip),%rsi
mov    $0x4,%edx
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1193 <main+0x43>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    0x2e6b(%rip),%rsi
call   1070 <signal@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    0x2e46(%rip),%rsi
call   1070 <signal@plt>
lea    0xe8f(%rip),%r14
mov    %rsp,%rbx
lea    0xe58(%rip),%r15
lea    0xe79(%rip),%r12
lea    0xe63(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x63,%edx
call   1050 <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   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1060 <strcmp@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 = [17 x i8] c"\0AType a message\0A\00"
@.str.1 = [25 x i8] c"read returned an error!\0A\00"
@.str.2 = [15 x i8] c"You typed: %s \00"
@.str.3 = [5 x i8] c"quit\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @SIGINT
%9 = call i32 @signal(i32 %8, void (i32)* @inthandler)
%10 = load i32, i32* @SIGQUIT
%11 = call i32 @signal(i32 %10, void (i32)* @quithandler)
br label %12
12: ; preds = %27, %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%15 = call i32 @read(i32 0, i8* %14, i32 99)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %26
20: ; preds = %12
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %22
store i8 0, i8* %23
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %20, %18
br label %27
27: ; preds = %26
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%30 = icmp ne i64 %29, 0
br i1 %30, label %12, label %31
31: ; preds = %27
%32 = load i32, i32* %3
ret i32 %32
}

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