#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 BUFSIZ;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  int fd = open("3.17.text", O_RDONLY);
  char buf[BUFSIZ * 2];
  read(fd, buf, BUFSIZ * 2);
  printf("3.17.text: %s\n", buf);
  int sleep_time = 20;
  while (sleep_time) {
    printf("%d to sleep...\n", sleep_time);
    sleep(1);
    --sleep_time;
  }
  read(fd, buf, BUFSIZ * 2);
  printf("3.17.text: %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)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
add    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
shl    $0x1,%edx
call   1040 <read@plt>
mov    -0x38(%rbp),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x14,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11fc <main+0xbc>
mov    -0x2c(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c9 <main+0x89>
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%edx
shl    $0x1,%edx
call   1040 <read@plt>
mov    -0x38(%rbp),%rsi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
lea    0xea2(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%r14d
mov    0x2e6b(%rip),%r13
mov    0x0(%r13),%edx
add    %edx,%edx
mov    %rsp,%r12
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r14d,%edi
mov    %r12,%rsi
call   1040 <read@plt>
lea    0xe74(%rip),%r15
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe6f(%rip),%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x13,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x12,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x11,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0xf,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0xe,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0xd,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0xc,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0xb,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    0x0(%r13),%edx
add    %edx,%edx
mov    %r14d,%edi
mov    %r12,%rsi
call   1040 <read@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2c0d(%rip),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"3.17.text\00"
@O_RDONLY = global i32 0
@BUFSIZ = global i32 0
@.str.1 = [15 x i8] c"3.17.text: %s\0A\00"
@.str.2 = [16 x i8] c"%d to sleep...\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 i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* @BUFSIZ
%13 = mul nsw i32 %12, 2
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %7
%16 = alloca i8, i64 %14
store i64 %14, i64* %8
%17 = load i32, i32* %6
%18 = load i32, i32* @BUFSIZ
%19 = mul nsw i32 %18, 2
%20 = call i32 @read(i32 %17, i8* %16, i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 20, i32* %9
br label %22
22: ; preds = %25, %2
%23 = load i32, i32* %9
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = call i32 @sleep(i32 1)
%29 = load i32, i32* %9
%30 = add nsw i32 %29, -1
store i32 %30, i32* %9
br label %22
31: ; preds = %22
%32 = load i32, i32* %6
%33 = load i32, i32* @BUFSIZ
%34 = mul nsw i32 %33, 2
%35 = call i32 @read(i32 %32, i8* %16, i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%37 = load i32, i32* @EXIT_SUCCESS
store i32 %37, i32* %3
%38 = load i8*, i8** %7
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [10 x i8] c"3.17.text\00"
@O_RDONLY = global i32 0
@BUFSIZ = global i32 0
@.str.1 = [15 x i8] c"3.17.text: %s\0A\00"
@.str.2 = [16 x i8] c"%d to sleep...\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @BUFSIZ
%6 = shl nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = call i32 @read(i32 %4, i8* %8, i32 %6)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 20)
%12 = call i32 @sleep(i32 1)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 19)
%14 = call i32 @sleep(i32 1)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 18)
%16 = call i32 @sleep(i32 1)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 17)
%18 = call i32 @sleep(i32 1)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 16)
%20 = call i32 @sleep(i32 1)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 15)
%22 = call i32 @sleep(i32 1)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 14)
%24 = call i32 @sleep(i32 1)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 13)
%26 = call i32 @sleep(i32 1)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 12)
%28 = call i32 @sleep(i32 1)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 11)
%30 = call i32 @sleep(i32 1)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 10)
%32 = call i32 @sleep(i32 1)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 9)
%34 = call i32 @sleep(i32 1)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 8)
%36 = call i32 @sleep(i32 1)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 7)
%38 = call i32 @sleep(i32 1)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 6)
%40 = call i32 @sleep(i32 1)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 5)
%42 = call i32 @sleep(i32 1)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 4)
%44 = call i32 @sleep(i32 1)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 3)
%46 = call i32 @sleep(i32 1)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 2)
%48 = call i32 @sleep(i32 1)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 1)
%50 = call i32 @sleep(i32 1)
%51 = load i32, i32* @BUFSIZ
%52 = shl nsw i32 %51, 1
%53 = call i32 @read(i32 %4, i8* %8, i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%55 = load i32, i32* @EXIT_SUCCESS
ret i32 %55
}