#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 STDIN_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("\tSleeps for specified number of seconds, then behaves like"
           " cat\n");
    return 1;
  }
  secs = (unsigned int)atoi(argv[1]);
  sleep(secs);
  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);
    }
  }
  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    12ae <main+0x12e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   10a0 <sleep@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1204 <main+0x84>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1050 <send_to_stdout@plt>
jmp    12a7 <main+0x127>
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12a2 <main+0x122>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1284 <main+0x104>
mov    0x2d93(%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    0xdf4(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12ae <main+0x12e>
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    120b <main+0x8b>
jmp    12a7 <main+0x127>
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    1261 <main+0xd1>
mov    %edi,%ebp
mov    0x8(%r14),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   10b0 <sleep@plt>
cmp    $0x2,%ebp
jne    11ee <main+0x5e>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
call   1060 <send_to_stdout@plt>
jmp    122b <main+0x9b>
mov    %ebp,%r15d
mov    $0x2,%ebx
mov    0x2deb(%rip),%r12
nopl   (%rax)
mov    (%r14,%rbx,8),%rdi
mov    (%r12),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     122f <main+0x9f>
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    1200 <main+0x70>
xor    %eax,%eax
jmp    1261 <main+0xd1>
mov    %ebx,%eax
mov    0x2da0(%rip),%rcx
mov    (%rcx),%ebp
mov    (%r14,%rax,8),%rbx
mov    $0xffffffff,%edi
call   10a0 <strerror@plt>
lea    0xdd8(%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"\09Sleeps for specified number of seconds, then behaves like cat\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"
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 %65
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @atoi(i8* %20)
%22 = trunc i64 %21 to i32
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = call i32 @sleep(i32 %23)
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %30
27: ; preds = %17
%28 = load i32, i32* @STDIN_FILENO
%29 = call i32 @send_to_stdout(i32 %28)
br label %64
30: ; preds = %17
store i32 2, i32* %7
br label %31
31: ; preds = %60, %30
%32 = load i32, i32* %7
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %63
35: ; preds = %31
%36 = load i8**, i8*** %5
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = load i32, i32* @O_RDONLY
%42 = call i32 @open(i8* %40, i32 %41)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %55
45: ; preds = %35
%46 = load i32, i32* @stderr
%47 = load i8**, i8*** %5
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = load i32, i32* %8
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %51, i8* %53)
store i32 2, i32* %3
br label %65
55: ; preds = %35
%56 = load i32, i32* %8
%57 = call i32 @send_to_stdout(i32 %56)
%58 = load i32, i32* %8
%59 = call i32 @close(i32 %58)
br label %60
60: ; preds = %55
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %31
63: ; preds = %31
br label %64
64: ; preds = %63, %27
store i32 0, i32* %3
br label %65
65: ; preds = %64, %45, %11
%66 = load i32, i32* %3
ret i32 %66
}

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"
@str = [63 x i8] c"\09Sleeps for specified number of seconds, then behaves like cat\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 %39
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atoi(i8* %10)
%12 = trunc i64 %11 to i32
%13 = tail call i32 @sleep(i32 %12)
%14 = icmp eq i32 %0, 2
br i1 %14, label %17, label %15
15: ; preds = %8
%16 = zext i32 %0 to i64
br label %20
17: ; preds = %8
%18 = load i32, i32* @STDIN_FILENO
%19 = tail call i32 @send_to_stdout(i32 %18)
br label %39
20: ; preds = %15, %34
%21 = phi i64 [ 2, %15 ], [ %37, %34 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = tail call i32 @open(i8* %23, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %34
27: ; preds = %20
%28 = and i64 %21, 4294967295
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %29
%32 = tail call i8* @strerror(i32 -1)
%33 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %32)
br label %39
34: ; preds = %20
%35 = tail call i32 @send_to_stdout(i32 %25)
%36 = tail call i32 @close(i32 %25)
%37 = add nuw nsw i64 %21, 1
%38 = icmp eq i64 %37, %16
br i1 %38, label %39, label %20
39: ; preds = %34, %17, %27, %4
%40 = phi i32 [ 1, %4 ], [ 2, %27 ], [ 0, %17 ], [ 0, %34 ]
ret i32 %40
}