#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 atoi(char *);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int read(int, char **, int);
int /*<<< orphan*/ write(int, char **, int);
int main(int argc, char **argv) {
  int n, N, fd;
  if (argc < 2) {
    printf("Please you have to specify the file name.\n");
    printf("./g141 <filename> <buffer_size>\n");
    return 1;
  } else {
    fd = open(argv[1], O_RDONLY, 0666);
  }
  if (argc < 3) {
    N = 1;
  } else {
    N = atoi(argv[2]);
  }
  char buf[N];
  while ((n = read(fd, &buf, N)) > 0) {
    write(1, &buf, N);
  }
  return 1;
}


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)
jge    1194 <main+0x44>
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123d <main+0xed>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c8 <main+0x78>
movl   $0x1,-0x18(%rbp)
jmp    11d8 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    122f <main+0xdf>
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    11fe <main+0xae>
movl   $0x1,-0x4(%rbp)
mov    -0x28(%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   %r12
push   %rbx
cmp    $0x1,%edi
jg     117a <main+0x2a>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
jmp    11f7 <main+0xa7>
mov    %rsi,%r12
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    $0x1b6,%edx
call   1060 <open@plt>
mov    %eax,%r14d
mov    $0x1,%r15d
cmp    $0x2,%ebx
je     11b1 <main+0x61>
mov    0x10(%r12),%rdi
call   1070 <atoi@plt>
mov    %eax,%r15d
mov    %rsp,%r12
mov    %r15d,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11f4 <main+0xa4>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <write@plt>
jmp    11d0 <main+0x80>
mov    %r12,%rsp
mov    $0x1,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Please you have to specify the file name.\0A\00"
@.str.1 = [33 x i8] c"./g141 <filename> <buffer_size>\0A\00"
@O_RDONLY = 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
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %48
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20, i32 438)
store i32 %21, i32* %8
br label %22
22: ; preds = %16
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 3
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 1, i32* %7
br label %31
26: ; preds = %22
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %7
br label %31
31: ; preds = %26, %25
%32 = load i32, i32* %7
%33 = zext i32 %32 to i64
%34 = call i8* @llvm.stacksave()
store i8* %34, i8** %9
%35 = alloca i8, i64 %33
store i64 %33, i64* %10
br label %36
36: ; preds = %42, %31
%37 = load i32, i32* %8
%38 = bitcast i8* %35 to i8**
%39 = load i32, i32* %7
%40 = call i32 @read(i32 %37, i8** %38, i32 %39)
store i32 %40, i32* %6
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %36
%43 = bitcast i8* %35 to i8**
%44 = load i32, i32* %7
%45 = call i32 @write(i32 1, i8** %43, i32 %44)
br label %36
46: ; preds = %36
store i32 1, i32* %3
%47 = load i8*, i8** %9
br label %48
48: ; preds = %46, %13
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@str = [42 x i8] c"Please you have to specify the file name.\00"
@str.2 = [32 x i8] c"./g141 <filename> <buffer_size>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.2, i64 0, i64 0))
br label %30
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10, i32 438)
%12 = icmp eq i32 %0, 2
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
br label %17
17: ; preds = %7, %13
%18 = phi i32 [ %16, %13 ], [ 1, %7 ]
%19 = zext i32 %18 to i64
%20 = tail call i8* @llvm.stacksave()
%21 = alloca i8, i64 %19
%22 = bitcast i8* %21 to i8**
%23 = call i32 @read(i32 %11, i8** %22, i32 %18)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %17, %25
%26 = call i32 @write(i32 1, i8** %22, i32 %18)
%27 = call i32 @read(i32 %11, i8** %22, i32 %18)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %25, label %29
29: ; preds = %25, %17
tail call void @llvm.stackrestore(i8* %20)
br label %30
30: ; preds = %29, %4
ret i32 1
}