#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, char **, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int write(int, ...);
int main(int argc, char *argv[]) {
  int fd1, num_read;
  char buffer[] = "Advanced Programming in the XXXX Environment.\n";
  char *filename = "test.txt";
  char sub_string[] = "UNIX";
  if ((fd1 = open(filename, O_RDWR | O_CREAT, 0644)) == -1) {
    fprintf(stderr, "Err. open(%s): %s\n", filename, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (write(fd1, &buffer, sizeof(buffer)) == -1) {
    fprintf(stderr, "Err. write(): %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("(%d byte) Before: %s", strlen(buffer), buffer);
  if (lseek(fd1, 28, SEEK_SET) == -1) {
    fprintf(stderr, "Err. lseek(): %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (write(fd1, sub_string, 4) == -1) {
    fprintf(stderr, "Err. write(): %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (lseek(fd1, -2, SEEK_END) == -1) {
    fprintf(stderr, "Err. lseek(): %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (write(fd1, "\0", 1) == -1) {
    fprintf(stderr, "Err. write(): %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  close(fd1);
  if ((fd1 = open(filename, O_RDONLY)) == -1) {
    fprintf(stderr, "Err. open(%s): %s\n", filename, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((num_read = read(fd1, &buffer, sizeof(buffer))) == -1) {
    fprintf(stderr, "Err. read(): %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("(%d byte)  After: ", strlen(buffer));
  fflush(stdout);
  if (write(STDOUT_FILENO, buffer, num_read) == -1) {
    fprintf(stderr, "Err. write(): %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  close(fd1);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe1c(%rip),%rsi
mov    $0x2f,%edx
call   10a0 <memcpy@plt>
lea    0xe3a(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xe39(%rip),%eax
mov    %eax,-0x5d(%rbp)
mov    0xe34(%rip),%al
mov    %al,-0x59(%rbp)
mov    -0x58(%rbp),%rdi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
mov    0x2dd9(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1281 <main+0xc1>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x2f,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    12d9 <main+0x119>
mov    0x2d14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x70(%rbp),%edi
mov    %rax,%rdx
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    -0x50(%rbp),%rdx
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2ca8(%rip),%rax
mov    (%rax),%edx
mov    $0x1c,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1351 <main+0x191>
mov    0x2c9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2c88(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rdx
lea    0xd3b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x5d(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    13a9 <main+0x1e9>
mov    0x2c44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x78(%rbp),%edi
mov    %rax,%rdx
lea    0xcbc(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2bfe(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2c1d(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffe,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1404 <main+0x244>
mov    0x2be9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    0x2bd5(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    %rax,%rdx
lea    0xc88(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2ba3(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    0xc9f(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    145f <main+0x29f>
mov    0x2b8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
mov    0x2b7a(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x80(%rbp),%edi
mov    %rax,%rdx
lea    0xc06(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2b48(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x58(%rbp),%rdi
mov    0x2b56(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    14db <main+0x31b>
mov    0x2b2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    0x2b08(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    %rax,%rcx
lea    0xb77(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2acc(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x2f,%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    153a <main+0x37a>
mov    0x2ab9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x90(%rbp)
mov    0x2aa2(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x90(%rbp),%edi
mov    %rax,%rdx
lea    0xb64(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2a6d(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    0xb4e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2a3e(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    0x2a80(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    15c3 <main+0x403>
mov    0x2a30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    0x2a19(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rdx
lea    0xaa2(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x29e4(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x29be(%rip),%rax
mov    (%rax),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
movups 0xe60(%rip),%xmm0
movups %xmm0,0x2f(%rsp)
movaps 0xe45(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe29(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0xc(%rsp)
movl   $0x58494e55,0x8(%rsp)
58
mov    0x2de8(%rip),%rax
mov    0x2e01(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe2d(%rip),%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     13ae <main+0x1fe>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    $0x2f,%edx
mov    %eax,%edi
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     136e <main+0x1be>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0xe19(%rip),%rdi
mov    %eax,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x1c,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     138e <main+0x1de>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     136e <main+0x1be>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0xfffffffe,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
je     138e <main+0x1de>
lea    0xdf9(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     136e <main+0x1be>
mov    %ebx,%edi
call   1070 <close@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%esi
lea    0xd4d(%rip),%rdi
xor    %eax,%eax
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     13ae <main+0x1fe>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x2f,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
je     13e1 <main+0x231>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xd76(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     136e <main+0x1be>
mov    %ebx,%edi
call   1070 <close@plt>
mov    0x2c2d(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2c43(%rip),%rax
mov    (%rax),%ebx
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xcc4(%rip),%rsi
jmp    13ff <main+0x24f>
mov    0x2c23(%rip),%rax
mov    (%rax),%ebx
mov    0x2c12(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xccb(%rip),%rsi
jmp    13ff <main+0x24f>
mov    0x2c03(%rip),%rax
mov    (%rax),%ebx
mov    0x2bf2(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xc71(%rip),%rsi
lea    0xc5c(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    140b <main+0x25b>
mov    0x2bd0(%rip),%rax
mov    (%rax),%ebx
mov    0x2bbf(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xc8a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2b8e(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@__const.main.buffer = [47 x i8] c"Advanced Programming in the XXXX Environment.\0A\00"
@.str = [9 x i8] c"test.txt\00"
@__const.main.sub_string = [5 x i8] c"UNIX\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Err. open(%s): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [18 x i8] c"Err. write(): %s\0A\00"
@.str.3 = [21 x i8] c"(%d byte) Before: %s\00"
@SEEK_SET = global i32 0
@.str.4 = [18 x i8] c"Err. lseek(): %s\0A\00"
@SEEK_END = global i32 0
@.str.5 = [2 x i8] zeroinitializer
@O_RDONLY = global i32 0
@.str.6 = [17 x i8] c"Err. read(): %s\0A\00"
@.str.7 = [19 x i8] c"(%d byte) After: \00"
@stdout = global i32 0
@STDOUT_FILENO = global i32 0
@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 i32
%8 = alloca [47 x i8]
%9 = alloca i8*
%10 = alloca [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [47 x i8]* %8 to i8*
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %9
%12 = bitcast [5 x i8]* %10 to i8*
%13 = load i8*, i8** %9
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = call i32 (i8*, i32, ...) @open(i8* %13, i32 %16, i32 420)
store i32 %17, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %27
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %9
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %2
%28 = load i32, i32* %6
%29 = call i32 (i32, ...) @write(i32 %28, [47 x i8]* %8, i64 47)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %38
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %27
%39 = getelementptr inbounds [47 x i8], [47 x i8]* %8, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = getelementptr inbounds [47 x i8], [47 x i8]* %8, i64 0, i64 0
%42 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %40, i8* %41)
%43 = load i32, i32* %6
%44 = load i32, i32* @SEEK_SET
%45 = call i32 @lseek(i32 %43, i32 28, i32 %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %54
47: ; preds = %38
%48 = load i32, i32* @stderr
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %38
%55 = load i32, i32* %6
%56 = getelementptr inbounds [5 x i8], [5 x i8]* %10, i64 0, i64 0
%57 = call i32 (i32, ...) @write(i32 %55, i8* %56, i32 4)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %66
59: ; preds = %54
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %62)
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %54
%67 = load i32, i32* %6
%68 = load i32, i32* @SEEK_END
%69 = call i32 @lseek(i32 %67, i32 -2, i32 %68)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %78
71: ; preds = %66
%72 = load i32, i32* @stderr
%73 = load i32, i32* @errno
%74 = call i8* @strerror(i32 %73)
%75 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %74)
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %66
%79 = load i32, i32* %6
%80 = call i32 (i32, ...) @write(i32 %79, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %89
82: ; preds = %78
%83 = load i32, i32* @stderr
%84 = load i32, i32* @errno
%85 = call i8* @strerror(i32 %84)
%86 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %85)
%87 = load i32, i32* @EXIT_FAILURE
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %78
%90 = load i32, i32* %6
%91 = call i32 @close(i32 %90)
%92 = load i8*, i8** %9
%93 = load i32, i32* @O_RDONLY
%94 = call i32 (i8*, i32, ...) @open(i8* %92, i32 %93)
store i32 %94, i32* %6
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %104
96: ; preds = %89
%97 = load i32, i32* @stderr
%98 = load i8*, i8** %9
%99 = load i32, i32* @errno
%100 = call i8* @strerror(i32 %99)
%101 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %98, i8* %100)
%102 = load i32, i32* @EXIT_FAILURE
%103 = call i32 @exit(i32 %102)
unreachable
104: ; preds = %89
%105 = load i32, i32* %6
%106 = bitcast [47 x i8]* %8 to i8**
%107 = call i32 @read(i32 %105, i8** %106, i32 47)
store i32 %107, i32* %7
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %116
109: ; preds = %104
%110 = load i32, i32* @stderr
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %112)
%114 = load i32, i32* @EXIT_FAILURE
%115 = call i32 @exit(i32 %114)
unreachable
116: ; preds = %104
%117 = getelementptr inbounds [47 x i8], [47 x i8]* %8, i64 0, i64 0
%118 = call i32 @strlen(i8* %117)
%119 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %118)
%120 = load i32, i32* @stdout
%121 = call i32 @fflush(i32 %120)
%122 = load i32, i32* @STDOUT_FILENO
%123 = getelementptr inbounds [47 x i8], [47 x i8]* %8, i64 0, i64 0
%124 = load i32, i32* %7
%125 = call i32 (i32, ...) @write(i32 %122, i8* %123, i32 %124)
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %134
127: ; preds = %116
%128 = load i32, i32* @stderr
%129 = load i32, i32* @errno
%130 = call i8* @strerror(i32 %129)
%131 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %130)
%132 = load i32, i32* @EXIT_FAILURE
%133 = call i32 @exit(i32 %132)
unreachable
134: ; preds = %116
%135 = load i32, i32* %6
%136 = call i32 @close(i32 %135)
%137 = load i32, i32* @EXIT_SUCCESS
ret i32 %137
}

LLVM IR (-O2):
@__const.main.buffer = [47 x i8] c"Advanced Programming in the XXXX Environment.\0A\00"
@.str = [9 x i8] c"test.txt\00"
@__const.main.sub_string = [5 x i8] c"UNIX\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Err. open(%s): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [18 x i8] c"Err. write(): %s\0A\00"
@.str.3 = [21 x i8] c"(%d byte) Before: %s\00"
@SEEK_SET = global i32 0
@.str.4 = [18 x i8] c"Err. lseek(): %s\0A\00"
@SEEK_END = global i32 0
@.str.5 = [2 x i8] zeroinitializer
@O_RDONLY = global i32 0
@.str.6 = [17 x i8] c"Err. read(): %s\0A\00"
@.str.7 = [19 x i8] c"(%d byte) After: \00"
@stdout = global i32 0
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [47 x i8]
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [47 x i8], [47 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_CREAT
%9 = or i32 %8, %7
%10 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9, i32 420)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = call i32 (i32, ...) @write(i32 %10, [47 x i8]* %3, i64 47)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %19
%30 = call i32 @strlen(i8* %5)
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %30, i8* %5)
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @lseek(i32 %10, i32 28, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %42
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %29
%43 = call i32 (i32, ...) @write(i32 %10, i8* %6, i32 4)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %52
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %42
%53 = load i32, i32* @SEEK_END
%54 = call i32 @lseek(i32 %10, i32 -2, i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %63
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %59)
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %52
%64 = call i32 (i32, ...) @write(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %73
66: ; preds = %63
%67 = load i32, i32* @stderr
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %69)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %63
%74 = call i32 @close(i32 %10)
%75 = load i32, i32* @O_RDONLY
%76 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %75)
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %85
78: ; preds = %73
%79 = load i32, i32* @stderr
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %81)
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %73
%86 = bitcast [47 x i8]* %3 to i8**
%87 = call i32 @read(i32 %76, i8** %86, i32 47)
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %96
89: ; preds = %85
%90 = load i32, i32* @stderr
%91 = load i32, i32* @errno
%92 = call i8* @strerror(i32 %91)
%93 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %92)
%94 = load i32, i32* @EXIT_FAILURE
%95 = call i32 @exit(i32 %94)
unreachable
96: ; preds = %85
%97 = call i32 @strlen(i8* %5)
%98 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %97)
%99 = load i32, i32* @stdout
%100 = call i32 @fflush(i32 %99)
%101 = load i32, i32* @STDOUT_FILENO
%102 = call i32 (i32, ...) @write(i32 %101, i8* %5, i32 %87)
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %111
104: ; preds = %96
%105 = load i32, i32* @stderr
%106 = load i32, i32* @errno
%107 = call i8* @strerror(i32 %106)
%108 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %107)
%109 = load i32, i32* @EXIT_FAILURE
%110 = call i32 @exit(i32 %109)
unreachable
111: ; preds = %96
%112 = call i32 @close(i32 %76)
%113 = load i32, i32* @EXIT_SUCCESS
ret i32 %113
}