#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ SIGINT;
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int (*)());
main() {
  int c, n;
  char buf[100];
  int onintr();
  signal(SIGINT, onintr);
  for (;;) {
    n = read(0, buf, 100);
    if (n > 0)
      printf(buf);
    else {
      if (errno == EINTR) {
        errno = 0;
        printf("interrupt side %d\n", n);
      } else {
        printf("true end of file %d\n", n);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
mov    0x2e89(%rip),%rsi
call   1050 <signal@plt>
lea    -0x70(%rbp),%rsi
xor    %edi,%edi
mov    $0x64,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1181 <main+0x51>
lea    -0x70(%rbp),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d5 <main+0xa5>
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%rax
jne    11bf <main+0x8f>
mov    0x2e2e(%rip),%rax
movq   $0x0,(%rax)
mov    -0xc(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d0 <main+0xa0>
mov    -0xc(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d5 <main+0xa5>
jmp    1154 <main+0x24>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
mov    0x2e8b(%rip),%rsi
call   1050 <signal@plt>
mov    %rsp,%rbx
mov    0x2e74(%rip),%r12
mov    0x2e65(%rip),%r13
lea    0xe96(%rip),%r14
lea    0xea2(%rip),%r15
jmp    118a <main+0x5a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1180 <main+0x50>
mov    (%r12),%rcx
cmp    0x0(%r13),%rcx
jne    11b4 <main+0x84>
movq   $0x0,(%r12)
mov    %r14,%rdi
jmp    11b7 <main+0x87>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    118a <main+0x5a>

LLVM IR (-O0):
@SIGINT = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str = [19 x i8] c"interrupt side %d\0A\00"
@.str.1 = [21 x i8] c"true end of file %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @SIGINT
%6 = call i32 @signal(i32 %5, i32 (...)* @onintr)
br label %7
7: ; preds = %26, %0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = call i32 @read(i32 0, i8* %8, i32 100)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* %13)
br label %26
15: ; preds = %7
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15
store i64 0, i64* @errno
%20 = load i32, i32* %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %25
22: ; preds = %15
%23 = load i32, i32* %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %19
br label %26
26: ; preds = %25, %12
br label %7
}

LLVM IR (-O2):
@SIGINT = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str = [19 x i8] c"interrupt side %d\0A\00"
@.str.1 = [21 x i8] c"true end of file %d\0A\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, i32 (...)* @onintr)
br label %5
5: ; preds = %16, %0
%6 = call i32 @read(i32 0, i8* %2, i32 100)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 (i8*, ...) @printf(i8* %2)
br label %16
10: ; preds = %5
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %10
store i64 0, i64* @errno
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %16
16: ; preds = %14, %17, %8
br label %5
17: ; preds = %10
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %16
}