#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  char buf[20 + 1];
  ssize_t numRead;
  if ((numRead = read(STDIN_FILENO, buf, 20)) == -1) {
    printf("could not read from stdin\n");
    exit(EXIT_FAILURE);
  }
  buf[numRead] = '\0';
  printf("input was %s\n", buf);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1040 <read@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
jne    1185 <main+0x55>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movslq -0x34(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x14,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
jne    1179 <main+0x39>
lea    0xea8(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xe7a(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [27 x i8] c"could not read from stdin\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"input was %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [21 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @STDIN_FILENO
%9 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 20)
store i32 %10, i32* %7
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_SUCCESS
%23 = call i32 @exit(i32 %22)
unreachable
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"input was %s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [26 x i8] c"could not read from stdin\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [21 x i8]
%4 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @read(i32 %5, i8* %4, i32 20)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = sext i32 %6 to i64
%14 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%16 = load i32, i32* @EXIT_SUCCESS
%17 = call i32 @exit(i32 %16)
unreachable
}