#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 EXIT_SUCCESS;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char buf[30 + 1];
  ssize_t num_read;
  if (argc <= 1) {
    fprintf(stderr, "Usage: %s <input data>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((num_read = read(STDIN_FILENO, buf, 30)) == -1) {
    fprintf(stderr, "Err. reading file: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  buf[num_read] = '\0';
  printf("Data: %s\n", buf);
  return (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)
cmpl   $0x1,-0x8(%rbp)
jg     119a <main+0x4a>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0x1e,%edx
call   1040 <read@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
jne    11f7 <main+0xa7>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xe34(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
movslq -0x34(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rsi
lea    0xe24(%rip),%rdi
call   1030 <printf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
cmp    $0x1,%edi
jle    1199 <main+0x49>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x1e,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     11ae <main+0x5e>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xead(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe54(%rip),%rsi
jmp    11d1 <main+0x81>
mov    0x2e2b(%rip),%rax
mov    (%rax),%ebx
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe4c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s <input data>\0A\00"
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = global i32 0
@.str.1 = [23 x i8] c"Err. reading file: %s\0A\00"
@errno = global i32 0
@.str.2 = [10 x i8] c"Data: %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 [31 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 1
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i32, i32* @STDIN_FILENO
%20 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 30)
store i32 %21, i32* %7
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %18
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 %32
store i8 0, i8* %33
%34 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 0
%35 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s <input data>\0A\00"
@EXIT_FAILURE = global i32 0
@STDIN_FILENO = global i32 0
@.str.1 = [23 x i8] c"Err. reading file: %s\0A\00"
@errno = global i32 0
@.str.2 = [10 x i8] c"Data: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [31 x i8]
%4 = getelementptr inbounds [31 x i8], [31 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = load i32, i32* @STDIN_FILENO
%14 = call i32 @read(i32 %13, i8* %4, i32 30)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %12
%24 = sext i32 %14 to i64
%25 = getelementptr inbounds [31 x i8], [31 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}