#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*/ O_RDONLY;
int STDERR_FILENO;
int STDIN_FILENO;
int STDOUT_FILENO;
scalar_t__ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send_to_stdout(int);
int /*<<< orphan*/ sleep(unsigned int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(int argc, char **argv) {
  unsigned int secs;
  if (argc < 2) {
    printf("usage:  %s secs [file1 [file2 [...]]]\n", argv[0]);
    printf("\tBehaves like cat, then sleeps for specified number of"
           " seconds\n");
    return 1;
  }
  if (argc == 2) {
    send_to_stdout(STDIN_FILENO);
  } else {
    int i, fd;
    for (i = 2; i < argc; i++) {
      fd = open(argv[i], O_RDONLY);
      if (fd == -1) {
        fprintf(stderr, "Couldn't open file \"%s\":  %s\n", argv[i],
                strerror(fd));
        return 2;
      }
      send_to_stdout(fd);
      close(fd);
    }
  }
  close(STDIN_FILENO);
  close(STDOUT_FILENO);
  close(STDERR_FILENO);
  secs = (unsigned int)atoi(argv[1]);
  sleep(secs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11cf <main+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d8 <main+0x158>
cmpl   $0x2,-0x8(%rbp)
jne    11ec <main+0x6c>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1050 <send_to_stdout@plt>
jmp    128f <main+0x10f>
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    128a <main+0x10a>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    126c <main+0xec>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe0c(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12d8 <main+0x158>
mov    -0x1c(%rbp),%edi
call   1050 <send_to_stdout@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11f3 <main+0x73>
jmp    128f <main+0x10f>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   10a0 <sleep@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
cmp    $0x1,%edi
jg     11c7 <main+0x37>
mov    (%r14),%rsi
lea    0xe56(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    128b <main+0xfb>
cmp    $0x2,%edi
jne    11dc <main+0x4c>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1060 <send_to_stdout@plt>
jmp    121b <main+0x8b>
mov    %edi,%r15d
mov    $0x2,%ebx
mov    0x2df5(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
mov    (%r12),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1259 <main+0xc9>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <send_to_stdout@plt>
mov    %ebp,%edi
call   1050 <close@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11f0 <main+0x60>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1050 <close@plt>
mov    0x8(%r14),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   10b0 <sleep@plt>
xor    %eax,%eax
jmp    128b <main+0xfb>
mov    %ebx,%eax
mov    0x2d6e(%rip),%rcx
mov    (%rcx),%ebp
mov    (%r14,%rax,8),%rbx
mov    $0xffffffff,%edi
call   10a0 <strerror@plt>
lea    0xdae(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    $0x2,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"usage: %s secs [file1 [file2 [...]]]\0A\00"
@.str.1 = [64 x i8] c"\09Behaves like cat, then sleeps for specified number of seconds\0A\00"
@STDIN_FILENO = global i32 0
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [30 x i8] c"Couldn't open file \22%s\22: %s\0A\00"
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %71
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @STDIN_FILENO
%22 = call i32 @send_to_stdout(i32 %21)
br label %57
23: ; preds = %17
store i32 2, i32* %7
br label %24
24: ; preds = %53, %23
%25 = load i32, i32* %7
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %56
28: ; preds = %24
%29 = load i8**, i8*** %5
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = load i32, i32* @O_RDONLY
%35 = call i32 @open(i8* %33, i32 %34)
store i32 %35, i32* %8
%36 = load i32, i32* %8
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %48
38: ; preds = %28
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = load i32, i32* %8
%46 = call i8* @strerror(i32 %45)
%47 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %46)
store i32 2, i32* %3
br label %71
48: ; preds = %28
%49 = load i32, i32* %8
%50 = call i32 @send_to_stdout(i32 %49)
%51 = load i32, i32* %8
%52 = call i32 @close(i32 %51)
br label %53
53: ; preds = %48
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %24
56: ; preds = %24
br label %57
57: ; preds = %56, %20
%58 = load i32, i32* @STDIN_FILENO
%59 = call i32 @close(i32 %58)
%60 = load i32, i32* @STDOUT_FILENO
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* @STDERR_FILENO
%63 = call i32 @close(i32 %62)
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i64 @atoi(i8* %66)
%68 = trunc i64 %67 to i32
store i32 %68, i32* %6
%69 = load i32, i32* %6
%70 = call i32 @sleep(i32 %69)
store i32 0, i32* %3
br label %71
71: ; preds = %57, %38, %11
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@.str = [39 x i8] c"usage: %s secs [file1 [file2 [...]]]\0A\00"
@STDIN_FILENO = global i32 0
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [30 x i8] c"Couldn't open file \22%s\22: %s\0A\00"
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@str = [63 x i8] c"\09Behaves like cat, then sleeps for specified number of seconds\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str, i64 0, i64 0))
br label %46
8: ; preds = %2
%9 = icmp eq i32 %0, 2
br i1 %9, label %12, label %10
10: ; preds = %8
%11 = zext i32 %0 to i64
br label %15
12: ; preds = %8
%13 = load i32, i32* @STDIN_FILENO
%14 = tail call i32 @send_to_stdout(i32 %13)
br label %34
15: ; preds = %10, %29
%16 = phi i64 [ 2, %10 ], [ %32, %29 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* %18, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %29
22: ; preds = %15
%23 = and i64 %16, 4294967295
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %24
%27 = tail call i8* @strerror(i32 -1)
%28 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %27)
br label %46
29: ; preds = %15
%30 = tail call i32 @send_to_stdout(i32 %20)
%31 = tail call i32 @close(i32 %20)
%32 = add nuw nsw i64 %16, 1
%33 = icmp eq i64 %32, %11
br i1 %33, label %34, label %15
34: ; preds = %29, %12
%35 = load i32, i32* @STDIN_FILENO
%36 = tail call i32 @close(i32 %35)
%37 = load i32, i32* @STDOUT_FILENO
%38 = tail call i32 @close(i32 %37)
%39 = load i32, i32* @STDERR_FILENO
%40 = tail call i32 @close(i32 %39)
%41 = getelementptr inbounds i8*, i8** %1, i64 1
%42 = load i8*, i8** %41
%43 = tail call i64 @atoi(i8* %42)
%44 = trunc i64 %43 to i32
%45 = tail call i32 @sleep(i32 %44)
br label %46
46: ; preds = %22, %34, %4
%47 = phi i32 [ 1, %4 ], [ 0, %34 ], [ 2, %22 ]
ret i32 %47
}