#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_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ raw(int);
int /*<<< orphan*/ readwrite(int /*<<< orphan*/, int, int, int);
int /*<<< orphan*/ reset(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  if (argc < 2)
    return 1;
  fd = open(argv[1], O_RDWR);
  if (fd < 0)
    return 1;
  raw(fd);
  raw(0);
  readwrite(0, 1, fd, fd);
  printf("\r\n\r\n");
  close(fd);
  reset(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    11fe <main+0x9e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11bb <main+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    11fe <main+0x9e>
mov    -0x14(%rbp),%edi
call   1050 <raw@plt>
xor    %edi,%edi
call   1050 <raw@plt>
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <readwrite@plt>
lea    0xe1d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1070 <reset@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebx
cmp    $0x2,%edi
jl     11bf <main+0x5f>
mov    0x8(%rsi),%rdi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     11bf <main+0x5f>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <raw@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <raw@plt>
xor    %edi,%edi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %ebp,%ecx
call   1040 <readwrite@plt>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1070 <reset@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [5 x i8] c"\0D\0A\0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 1, i32* %3
br label %30
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDWR
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %10
store i32 1, i32* %3
br label %30
19: ; preds = %10
%20 = load i32, i32* %6
%21 = call i32 @raw(i32 %20)
%22 = call i32 @raw(i32 0)
%23 = load i32, i32* %6
%24 = load i32, i32* %6
%25 = call i32 @readwrite(i32 0, i32 1, i32 %23, i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
%29 = call i32 @reset(i32 0)
store i32 0, i32* %3
br label %30
30: ; preds = %19, %18, %9
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@str = [4 x i8] c"\0D\0A\0D\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDWR
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %4
%11 = tail call i32 @raw(i32 %8)
%12 = tail call i32 @raw(i32 0)
%13 = tail call i32 @readwrite(i32 0, i32 1, i32 %8, i32 %8)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @close(i32 %8)
%16 = tail call i32 @reset(i32 0)
br label %17
17: ; preds = %4, %2, %10
%18 = phi i32 [ 0, %10 ], [ 1, %2 ], [ 1, %4 ]
ret i32 %18
}