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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
size_t read(int, char *, int);
int /*<<< orphan*/ sleep(int);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int input_fd;
  ssize_t num_read;
  char buffer[20 + 1];
  if (argc != 2 || strcmp(argv[1], "--help") == 0) {
    printf("%s file\n", argv[0]);
    exit(1);
  }
  input_fd = open(argv[1], O_RDONLY);
  if (input_fd == -1) {
    perror("open error");
    exit(1);
  }
  while ((num_read = read(input_fd, buffer, 20)) > 0) {
    buffer[num_read] = '\0';
    printf("The input data was: %s\n", buffer);
    sleep(1);
  }
  if (close(input_fd == -1)) {
    perror("close file fd error");
    exit(1);
  }
  return 0;
}


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   $0x2,-0x8(%rbp)
jne    11be <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11db <main+0x5b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1214 <main+0x94>
lea    0xe0b(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1219 <main+0x99>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x14,%edx
call   1050 <read@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jbe    1260 <main+0xe0>
mov    -0x20(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rsi
lea    0xdcf(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    1219 <main+0x99>
cmpl   $0xffffffff,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     1291 <main+0x111>
lea    0xdb1(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1234 <main+0xb4>
mov    0x8(%rbx),%rdi
lea    0xe61(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1234 <main+0xb4>
mov    0x8(%rbx),%rdi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     124d <main+0xcd>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x14,%edx
call   1050 <read@plt>
test   %rax,%rax
je     121d <main+0x9d>
lea    0xe36(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x14,%edx
call   1050 <read@plt>
test   %rax,%rax
jne    11f0 <main+0x70>
xor    %edi,%edi
call   1040 <close@plt>
test   %rax,%rax
jne    1256 <main+0xd6>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xdc9(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdbc(%rip),%rdi
jmp    125d <main+0xdd>
lea    0xdd6(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [9 x i8] c"%s file\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [11 x i8] c"open error\00"
@.str.3 = [24 x i8] c"The input data was: %s\0A\00"
@.str.4 = [20 x i8] c"close file fd error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca [21 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %11, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %11
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %26, i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %23
br label %35
35: ; preds = %40, %34
%36 = load i32, i32* %6
%37 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%38 = call i64 @read(i32 %36, i8* %37, i32 20)
store i64 %38, i64* %7
%39 = icmp ugt i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %35
%41 = load i64, i64* %7
%42 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 %41
store i8 0, i8* %42
%43 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%44 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %43)
%45 = call i32 @sleep(i32 1)
br label %35
46: ; preds = %35
%47 = load i32, i32* %6
%48 = icmp eq i32 %47, -1
%49 = zext i1 %48 to i32
%50 = call i64 @close(i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %46
%53 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %46
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.1 = [9 x i8] c"%s file\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [11 x i8] c"open error\00"
@.str.3 = [24 x i8] c"The input data was: %s\0A\00"
@.str.4 = [20 x i8] c"close file fd error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [21 x i8]
%4 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %6, %2
%12 = load i8*, i8** %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %6
%16 = load i8*, i8** %7
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @open(i8* %16, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = call i64 @read(i32 %18, i8* %4, i32 20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %33, label %26
23: ; preds = %15
%24 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %20, %26
%27 = phi i64 [ %31, %26 ], [ %21, %20 ]
%28 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%30 = call i32 @sleep(i32 1)
%31 = call i64 @read(i32 %18, i8* %4, i32 20)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %26
33: ; preds = %26, %20
%34 = call i64 @close(i32 0)
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %33
ret i32 0
}