#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
scalar_t__ fork();
int /*<<< orphan*/ fstat(int, struct stat *);
scalar_t__ islower(char);
char *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char, char, char);
int /*<<< orphan*/ sleep(int);
char tolower(char);
char toupper(char);
int main() {
  int fd = open("file", O_RDWR);
  if (fd == -1) {
    perror("open");
    return 1;
  }
  struct stat s;
  fstat(fd, &s);
  char *p = mmap(NULL, s.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
  if (fork() == 0) {
    int i;
    for (i = 0; i < 3; i++) {
      if (islower(p[i]))
        p[i] = toupper(p[i]);
      else
        p[i] = tolower(p[i]);
    }
    sleep(5);
  } else {
    int i;
    sleep(2);
    printf("%c%c%c\n", p[0], p[1], p[2]);
    for (i = 5; i < 9; i++) {
      if (islower(p[i]))
        p[i] = toupper(p[i]);
      else
        p[i] = tolower(p[i]);
    }
  }
  munmap(p, s.st_size);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
lea    0xe21(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1209 <main+0x49>
lea    0xe0d(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b1 <main+0x1f1>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   10d0 <fstat@plt>
mov    -0x10(%rbp),%esi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
mov    0x2da8(%rip),%rax
or     (%rax),%edx
mov    0x2d97(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   10e0 <fork@plt>
cmp    $0x0,%rax
jne    12e7 <main+0x127>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    12d8 <main+0x118>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     12a7 <main+0xe7>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <toupper@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    12c5 <main+0x105>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1080 <tolower@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    12ca <main+0x10a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125f <main+0x9f>
mov    $0x5,%edi
call   10c0 <sleep@plt>
jmp    139d <main+0x1dd>
mov    $0x2,%edi
call   10c0 <sleep@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%dl
mov    -0x18(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x18(%rbp),%rax
lea    0xd01(%rip),%rdi
movsbl %dl,%esi
movsbl %cl,%edx
movsbl 0x2(%rax),%ecx
call   1060 <printf@plt>
movl   $0x5,-0x20(%rbp)
cmpl   $0x9,-0x20(%rbp)
jge    1398 <main+0x1d8>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     1367 <main+0x1a7>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <toupper@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1385 <main+0x1c5>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1080 <tolower@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    138a <main+0x1ca>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    131f <main+0x15f>
jmp    139d <main+0x1dd>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1090 <munmap@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    0xe28(%rip),%rdi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     1373 <main+0x1b3>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10d0 <fstat@plt>
mov    0x8(%rsp),%r14d
mov    0x2df8(%rip),%rax
mov    0x2dc9(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2db6(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
je     1270 <main+0xb0>
mov    $0x2,%edi
call   10c0 <sleep@plt>
movsbl 0x0(%rbp),%esi
movsbl 0x1(%rbp),%edx
movsbl 0x2(%rbp),%ecx
lea    0xdba(%rip),%rdi
call   1060 <printf@plt>
movsbl 0x5(%rbp),%edi
call   1030 <islower@plt>
mov    0x5(%rbp),%cl
movsbl %cl,%edi
test   %rax,%rax
je     128b <main+0xcb>
call   1040 <toupper@plt>
jmp    1290 <main+0xd0>
movsbl 0x0(%rbp),%edi
call   1030 <islower@plt>
mov    0x0(%rbp),%cl
movsbl %cl,%edi
test   %rax,%rax
je     12fe <main+0x13e>
call   1040 <toupper@plt>
jmp    1303 <main+0x143>
call   1080 <tolower@plt>
mov    %al,0x5(%rbp)
movsbl 0x6(%rbp),%edi
call   1030 <islower@plt>
mov    0x6(%rbp),%cl
movsbl %cl,%edi
test   %rax,%rax
je     12ae <main+0xee>
call   1040 <toupper@plt>
jmp    12b3 <main+0xf3>
call   1080 <tolower@plt>
mov    %al,0x6(%rbp)
movsbl 0x7(%rbp),%edi
call   1030 <islower@plt>
mov    0x7(%rbp),%cl
movsbl %cl,%edi
test   %rax,%rax
je     12d1 <main+0x111>
call   1040 <toupper@plt>
jmp    12d6 <main+0x116>
call   1080 <tolower@plt>
mov    %al,0x7(%rbp)
movsbl 0x8(%rbp),%edi
call   1030 <islower@plt>
mov    0x8(%rbp),%cl
movsbl %cl,%edi
test   %rax,%rax
je     12f4 <main+0x134>
call   1040 <toupper@plt>
jmp    12f9 <main+0x139>
call   1080 <tolower@plt>
mov    %al,0x8(%rbp)
jmp    1356 <main+0x196>
call   1080 <tolower@plt>
mov    %al,0x0(%rbp)
movsbl 0x1(%rbp),%edi
call   1030 <islower@plt>
mov    0x1(%rbp),%cl
movsbl %cl,%edi
test   %rax,%rax
je     1321 <main+0x161>
call   1040 <toupper@plt>
jmp    1326 <main+0x166>
call   1080 <tolower@plt>
mov    %al,0x1(%rbp)
movsbl 0x2(%rbp),%edi
call   1030 <islower@plt>
mov    0x2(%rbp),%cl
movsbl %cl,%edi
test   %rax,%rax
je     1344 <main+0x184>
call   1040 <toupper@plt>
jmp    1349 <main+0x189>
call   1080 <tolower@plt>
mov    %al,0x2(%rbp)
mov    $0x5,%edi
call   10c0 <sleep@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1090 <munmap@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xc8b(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%eax
jmp    136a <main+0x1aa>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"file\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@.str.2 = [8 x i8] c"%c%c%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %123
13: ; preds = %0
%14 = load i32, i32* %2
%15 = call i32 @fstat(i32 %14, %struct.stat* %3)
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i32, i32* @PROT_READ
%19 = load i32, i32* @PROT_WRITE
%20 = or i32 %18, %19
%21 = load i32, i32* @MAP_PRIVATE
%22 = load i32, i32* %2
%23 = call i8* @mmap(i32* null, i32 %17, i32 %20, i32 %21, i32 %22, i32 0)
store i8* %23, i8** %4
%24 = call i64 (...) @fork()
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %66
26: ; preds = %13
store i32 0, i32* %5
br label %27
27: ; preds = %61, %26
%28 = load i32, i32* %5
%29 = icmp slt i32 %28, 3
br i1 %29, label %30, label %64
30: ; preds = %27
%31 = load i8*, i8** %4
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = call i64 @islower(i8 signext %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %49
38: ; preds = %30
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = call signext i8 @toupper(i8 signext %43)
%45 = load i8*, i8** %4
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 %44, i8* %48
br label %60
49: ; preds = %30
%50 = load i8*, i8** %4
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = call signext i8 @tolower(i8 signext %54)
%56 = load i8*, i8** %4
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 %55, i8* %59
br label %60
60: ; preds = %49, %38
br label %61
61: ; preds = %60
%62 = load i32, i32* %5
%63 = add nsw i32 %62, 1
store i32 %63, i32* %5
br label %27
64: ; preds = %27
%65 = call i32 @sleep(i32 5)
br label %116
66: ; preds = %13
%67 = call i32 @sleep(i32 2)
%68 = load i8*, i8** %4
%69 = getelementptr inbounds i8, i8* %68, i64 0
%70 = load i8, i8* %69
%71 = load i8*, i8** %4
%72 = getelementptr inbounds i8, i8* %71, i64 1
%73 = load i8, i8* %72
%74 = load i8*, i8** %4
%75 = getelementptr inbounds i8, i8* %74, i64 2
%76 = load i8, i8* %75
%77 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext %70, i8 signext %73, i8 signext %76)
store i32 5, i32* %6
br label %78
78: ; preds = %112, %66
%79 = load i32, i32* %6
%80 = icmp slt i32 %79, 9
br i1 %80, label %81, label %115
81: ; preds = %78
%82 = load i8*, i8** %4
%83 = load i32, i32* %6
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
%86 = load i8, i8* %85
%87 = call i64 @islower(i8 signext %86)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %100
89: ; preds = %81
%90 = load i8*, i8** %4
%91 = load i32, i32* %6
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %90, i64 %92
%94 = load i8, i8* %93
%95 = call signext i8 @toupper(i8 signext %94)
%96 = load i8*, i8** %4
%97 = load i32, i32* %6
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
store i8 %95, i8* %99
br label %111
100: ; preds = %81
%101 = load i8*, i8** %4
%102 = load i32, i32* %6
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8, i8* %101, i64 %103
%105 = load i8, i8* %104
%106 = call signext i8 @tolower(i8 signext %105)
%107 = load i8*, i8** %4
%108 = load i32, i32* %6
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %107, i64 %109
store i8 %106, i8* %110
br label %111
111: ; preds = %100, %89
br label %112
112: ; preds = %111
%113 = load i32, i32* %6
%114 = add nsw i32 %113, 1
store i32 %114, i32* %6
br label %78
115: ; preds = %78
br label %116
116: ; preds = %115, %64
%117 = load i8*, i8** %4
%118 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%119 = load i32, i32* %118
%120 = call i32 @munmap(i8* %117, i32 %119)
%121 = load i32, i32* %2
%122 = call i32 @close(i32 %121)
br label %123
123: ; preds = %116, %11
%124 = load i32, i32* %1
ret i32 %124
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"file\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@.str.2 = [8 x i8] c"%c%c%c\0A\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 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 ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %108
7: ; preds = %0
%8 = bitcast %struct.stat* %1 to i8*
%9 = call i32 @fstat(i32 %3, %struct.stat* %1)
%10 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @PROT_WRITE
%14 = or i32 %13, %12
%15 = load i32, i32* @MAP_PRIVATE
%16 = tail call i8* @mmap(i32* null, i32 %11, i32 %14, i32 %15, i32 %3, i32 0)
%17 = tail call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %53
19: ; preds = %7
%20 = load i8, i8* %16
%21 = tail call i64 @islower(i8 signext %20)
%22 = icmp eq i64 %21, 0
%23 = load i8, i8* %16
br i1 %22, label %26, label %24
24: ; preds = %19
%25 = tail call signext i8 @toupper(i8 signext %23)
br label %28
26: ; preds = %19
%27 = tail call signext i8 @tolower(i8 signext %23)
br label %28
28: ; preds = %24, %26
%29 = phi i8 [ %27, %26 ], [ %25, %24 ]
store i8 %29, i8* %16
%30 = getelementptr inbounds i8, i8* %16, i64 1
%31 = load i8, i8* %30
%32 = tail call i64 @islower(i8 signext %31)
%33 = icmp eq i64 %32, 0
%34 = load i8, i8* %30
br i1 %33, label %37, label %35
35: ; preds = %28
%36 = tail call signext i8 @toupper(i8 signext %34)
br label %39
37: ; preds = %28
%38 = tail call signext i8 @tolower(i8 signext %34)
br label %39
39: ; preds = %37, %35
%40 = phi i8 [ %38, %37 ], [ %36, %35 ]
store i8 %40, i8* %30
%41 = getelementptr inbounds i8, i8* %16, i64 2
%42 = load i8, i8* %41
%43 = tail call i64 @islower(i8 signext %42)
%44 = icmp eq i64 %43, 0
%45 = load i8, i8* %41
br i1 %44, label %48, label %46
46: ; preds = %39
%47 = tail call signext i8 @toupper(i8 signext %45)
br label %50
48: ; preds = %39
%49 = tail call signext i8 @tolower(i8 signext %45)
br label %50
50: ; preds = %48, %46
%51 = phi i8 [ %49, %48 ], [ %47, %46 ]
store i8 %51, i8* %41
%52 = tail call i32 @sleep(i32 5)
br label %105
53: ; preds = %7
%54 = tail call i32 @sleep(i32 2)
%55 = load i8, i8* %16
%56 = getelementptr inbounds i8, i8* %16, i64 1
%57 = load i8, i8* %56
%58 = getelementptr inbounds i8, i8* %16, i64 2
%59 = load i8, i8* %58
%60 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext %55, i8 signext %57, i8 signext %59)
%61 = getelementptr inbounds i8, i8* %16, i64 5
%62 = load i8, i8* %61
%63 = tail call i64 @islower(i8 signext %62)
%64 = icmp eq i64 %63, 0
%65 = load i8, i8* %61
br i1 %64, label %68, label %66
66: ; preds = %53
%67 = tail call signext i8 @toupper(i8 signext %65)
br label %70
68: ; preds = %53
%69 = tail call signext i8 @tolower(i8 signext %65)
br label %70
70: ; preds = %66, %68
%71 = phi i8 [ %69, %68 ], [ %67, %66 ]
store i8 %71, i8* %61
%72 = getelementptr inbounds i8, i8* %16, i64 6
%73 = load i8, i8* %72
%74 = tail call i64 @islower(i8 signext %73)
%75 = icmp eq i64 %74, 0
%76 = load i8, i8* %72
br i1 %75, label %79, label %77
77: ; preds = %70
%78 = tail call signext i8 @toupper(i8 signext %76)
br label %81
79: ; preds = %70
%80 = tail call signext i8 @tolower(i8 signext %76)
br label %81
81: ; preds = %79, %77
%82 = phi i8 [ %80, %79 ], [ %78, %77 ]
store i8 %82, i8* %72
%83 = getelementptr inbounds i8, i8* %16, i64 7
%84 = load i8, i8* %83
%85 = tail call i64 @islower(i8 signext %84)
%86 = icmp eq i64 %85, 0
%87 = load i8, i8* %83
br i1 %86, label %90, label %88
88: ; preds = %81
%89 = tail call signext i8 @toupper(i8 signext %87)
br label %92
90: ; preds = %81
%91 = tail call signext i8 @tolower(i8 signext %87)
br label %92
92: ; preds = %90, %88
%93 = phi i8 [ %91, %90 ], [ %89, %88 ]
store i8 %93, i8* %83
%94 = getelementptr inbounds i8, i8* %16, i64 8
%95 = load i8, i8* %94
%96 = tail call i64 @islower(i8 signext %95)
%97 = icmp eq i64 %96, 0
%98 = load i8, i8* %94
br i1 %97, label %101, label %99
99: ; preds = %92
%100 = tail call signext i8 @toupper(i8 signext %98)
br label %103
101: ; preds = %92
%102 = tail call signext i8 @tolower(i8 signext %98)
br label %103
103: ; preds = %101, %99
%104 = phi i8 [ %102, %101 ], [ %100, %99 ]
store i8 %104, i8* %94
br label %105
105: ; preds = %103, %50
%106 = tail call i32 @munmap(i8* %16, i32 %11)
%107 = tail call i32 @close(i32 %3)
br label %108
108: ; preds = %105, %5
%109 = phi i32 [ 1, %5 ], [ 0, %105 ]
ret i32 %109
}