#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*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ STDERR_FILENO;
int errno;
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int /*<<< orphan*/ sleep(int);
char *strerror(int);
size_t strlen(char const *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char const *, size_t);
int main(void) {
  const char *buf = "hello,world.\n";
  size_t count = strlen(buf);
  int i1 = 2;
  scanf("%d", &i1);
  printf("%d\n", i1);
  write(STDERR_FILENO, buf, count);
  write(STDERR_FILENO, buf, count);
  int r = fcntl(STDERR_FILENO, F_SETFL, O_NONBLOCK);
  if (r == -1) {
    printf("%s(%d)\n", strerror(errno), errno);
  }
  int ret;
  ret = scanf("%d", &i1);
  if (ret != 1) {
    printf("%s(%d)\n", strerror(errno), errno);
  }
  while (1) {
    write(STDERR_FILENO, buf, count);
    printf("%d\n", i1);
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
lea    0xe69(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <write@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <write@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1240 <main+0xd0>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdc7(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <scanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     1285 <main+0x115>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
mov    0x2d5b(%rip),%rax
mov    (%rax),%edx
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    128a <main+0x11a>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <write@plt>
mov    -0x1c(%rbp),%esi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    128a <main+0x11a>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x2,0xc(%rsp)
lea    0xe96(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e2d(%rip),%r15
mov    (%r15),%edi
lea    0xe5b(%rip),%rbx
mov    $0xd,%edx
mov    %rbx,%rsi
call   1040 <write@plt>
mov    (%r15),%edi
mov    $0xd,%edx
mov    %rbx,%rsi
call   1040 <write@plt>
mov    (%r15),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1202 <main+0xa2>
mov    0x2de8(%rip),%rbx
mov    (%rbx),%edi
call   1070 <strerror@plt>
mov    (%rbx),%edx
lea    0xe1d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe05(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     1239 <main+0xd9>
mov    0x2db1(%rip),%rbx
mov    (%rbx),%edi
call   1070 <strerror@plt>
mov    (%rbx),%edx
lea    0xde6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdc0(%rip),%r14
lea    0xdca(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    $0xd,%edx
mov    %r14,%rsi
call   1040 <write@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    1250 <main+0xf0>

LLVM IR (-O0):
@.str = [14 x i8] c"hello,world.\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@STDERR_FILENO = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.3 = [8 x i8] c"%s(%d)\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %3
store i32 2, i32* %4
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%10 = load i32, i32* %4
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @STDERR_FILENO
%13 = load i8*, i8** %2
%14 = load i64, i64* %3
%15 = call i32 @write(i32 %12, i8* %13, i64 %14)
%16 = load i32, i32* @STDERR_FILENO
%17 = load i8*, i8** %2
%18 = load i64, i64* %3
%19 = call i32 @write(i32 %16, i8* %17, i64 %18)
%20 = load i32, i32* @STDERR_FILENO
%21 = load i32, i32* @F_SETFL
%22 = load i32, i32* @O_NONBLOCK
%23 = call i32 @fcntl(i32 %20, i32 %21, i32 %22)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %0
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = load i32, i32* @errno
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %28, i32 %29)
br label %31
31: ; preds = %26, %0
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 1
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = load i32, i32* @errno
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %37, i32 %38)
br label %40
40: ; preds = %35, %31
br label %41
41: ; preds = %40, %41
%42 = load i32, i32* @STDERR_FILENO
%43 = load i8*, i8** %2
%44 = load i64, i64* %3
%45 = call i32 @write(i32 %42, i8* %43, i64 %44)
%46 = load i32, i32* %4
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = call i32 @sleep(i32 1)
br label %41
}

LLVM IR (-O2):
@.str = [14 x i8] c"hello,world.\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@STDERR_FILENO = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.3 = [8 x i8] c"%s(%d)\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 2, i32* %1
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @STDERR_FILENO
%7 = call i32 @write(i32 %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 13)
%8 = load i32, i32* @STDERR_FILENO
%9 = call i32 @write(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 13)
%10 = load i32, i32* @STDERR_FILENO
%11 = load i32, i32* @F_SETFL
%12 = load i32, i32* @O_NONBLOCK
%13 = call i32 @fcntl(i32 %10, i32 %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %20
15: ; preds = %0
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = load i32, i32* @errno
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %17, i32 %18)
br label %20
20: ; preds = %15, %0
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%22 = icmp eq i32 %21, 1
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = load i32, i32* @errno
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %25, i32 %26)
br label %28
28: ; preds = %23, %20
br label %29
29: ; preds = %28, %29
%30 = load i32, i32* @STDERR_FILENO
%31 = call i32 @write(i32 %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 13)
%32 = load i32, i32* %1
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = call i32 @sleep(i32 1)
br label %29
}