#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 STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd = open("letter", O_RDWR);
  if (fd == -1) {
    perror("letter");
    return 1;
  }
  char c;
  read(fd, &c, 1);
  write(STDOUT_FILENO, &c, 1);
  write(fd, "*", 1);
  read(fd, &c, 1);
  write(STDOUT_FILENO, &c, 1);
  write(fd, "*", 1);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1199 <main+0x49>
lea    0xe78(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1219 <main+0xc9>
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe3c(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe00(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11fe <main+0xae>
mov    %eax,%ebx
lea    0x7(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    0x2e5d(%rip),%r12
mov    (%r12),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
lea    0xe5c(%rip),%r15
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    (%r12),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdfb(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11f2 <main+0xa2>

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

LLVM IR (-O2):
@.str = [7 x i8] c"letter\00"
@O_RDWR = global i32 0
@STDOUT_FILENO = global i32 0
@.str.1 = [2 x i8] c"*\00"
define i32 @main() {
%1 = alloca i8
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
7: ; preds = %0
%8 = call i32 @read(i32 %3, i8* %1, i32 1)
%9 = load i32, i32* @STDOUT_FILENO
%10 = call i32 @write(i32 %9, i8* %1, i32 1)
%11 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%12 = call i32 @read(i32 %3, i8* %1, i32 1)
%13 = load i32, i32* @STDOUT_FILENO
%14 = call i32 @write(i32 %13, i8* %1, i32 1)
%15 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%16 = tail call i32 @close(i32 %3)
br label %17
17: ; preds = %7, %5
%18 = phi i32 [ 1, %5 ], [ 0, %7 ]
ret i32 %18
}