#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*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_SYNC;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ exit(int);
scalar_t__ fcntl(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ fdatasync(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fsync(int /*<<< orphan*/);
int getopt(int, char **, char *);
int /*<<< orphan*/ isprint(int);
int optopt;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int write(int /*<<< orphan*/, char *, int);
int main(int argc, char **argv) {
  int n, c;
  char buf[512];
  int flags;
  int osync_on = 0, fsync_on = 0, fdatasync_on = 0;
  if (argc < 2) {
    printf("usage: %s -{a|b|c|d} < LARGEFILE_IN > LARGEFILE_OUT \n", argv[0]);
    printf(" -a for add O_SYNC flag\n");
    printf(" -b for removing O_SYNC flag\n");
    printf(" -c for add fsync call\n");
    printf(" -d for add fdatasync call (doesnot work in OSX)\n");
    return 0;
  }
  while ((c = getopt(argc, argv, "abcdh")) != -1) {
    switch (c) {
    case 'a':
      printf("O_SYNC is on\n");
      osync_on = 1;
      break;
    case 'b':
      printf("O_SYNC is off\n");
      osync_on = 0;
      break;
    case 'c':
      printf("O_SYNC is off, writes are followed by fsync\n");
      fsync_on = 1;
      break;
    case 'd':
      printf("O_SYNC is off, writes are followed by fdatasync\n");
      fdatasync_on = 1;
      break;
    case 'h':
      printf("usage: %s -{a|b|c|d} < LARGEFILE_IN > LARGEFILE_OUT \n", argv[0]);
      printf("Options are a, b, c, d\n");
      printf(" -a for add O_SYNC flag\n");
      printf(" -b for removing O_SYNC flag\n");
      printf(" -c for add fsync call\n");
      printf(" -d for add fdatasync call (doesnot work in OSX)\n");
      return 0;
    case '?':
      if (isprint(optopt))
        fprintf(stderr, "Unknown option `-%c'.\n", optopt);
      else
        fprintf(stderr, "Unknown option `\\x%x'.\n", optopt);
      return 1;
    default:
      abort();
    }
  }
  if ((flags = fcntl(STDOUT_FILENO, F_GETFL, 0)) < 0) {
    perror("Can't get file descriptor flags");
    exit(1);
  }
  if (osync_on == 1)
    flags |= O_SYNC;
  if (fcntl(STDOUT_FILENO, F_SETFL, flags) < 0) {
    perror("Can't set file descriptor flags");
    exit(1);
  }
  while ((n = read(STDIN_FILENO, buf, 512)) > 0) {
    if (write(STDOUT_FILENO, buf, n) != n) {
      fprintf(stderr, "write error\n");
      exit(1);
    }
    if (fsync_on == 1)
      fsync(STDOUT_FILENO);
    if (fdatasync_on == 1)
      fdatasync(STDOUT_FILENO);
  }
  if (n < 0) {
    fprintf(stderr, "read error\n");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x228(%rbp)
movl   $0x0,-0x22c(%rbp)
movl   $0x0,-0x230(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    125a <main+0x9a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xee6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1573 <main+0x3b3>
jmp    125f <main+0x9f>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xef2(%rip),%rdx
call   10d0 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     13fc <main+0x23c>
mov    -0x18(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x238(%rbp)
sub    $0x29,%eax
ja     13f0 <main+0x230>
mov    -0x238(%rbp),%rax
lea    0xd5c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x228(%rbp)
jmp    13f7 <main+0x237>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x228(%rbp)
jmp    13f7 <main+0x237>
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x22c(%rbp)
jmp    13f7 <main+0x237>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x230(%rbp)
jmp    13f7 <main+0x237>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1573 <main+0x3b3>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
call   10a0 <isprint@plt>
cmp    $0x0,%eax
je     13c4 <main+0x204>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
mov    0x2c29(%rip),%rax
mov    (%rax),%edx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    13e4 <main+0x224>
mov    0x2bfd(%rip),%rax
mov    (%rax),%edi
mov    0x2c04(%rip),%rax
mov    (%rax),%edx
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1573 <main+0x3b3>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    125f <main+0x9f>
mov    0x2bed(%rip),%rax
mov    (%rax),%edi
mov    0x2bac(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <fcntl@plt>
mov    %eax,-0x224(%rbp)
cmp    $0x0,%eax
jge    143a <main+0x27a>
lea    0xdfc(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmpl   $0x1,-0x228(%rbp)
jne    145c <main+0x29c>
mov    0x2b92(%rip),%rax
mov    (%rax),%eax
or     -0x224(%rbp),%eax
mov    %eax,-0x224(%rbp)
mov    0x2b8d(%rip),%rax
mov    (%rax),%edi
mov    0x2b54(%rip),%rax
mov    (%rax),%esi
mov    -0x224(%rbp),%edx
call   1050 <fcntl@plt>
cmp    $0x0,%rax
jge    1499 <main+0x2d9>
lea    0xdbd(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    149e <main+0x2de>
mov    0x2b0b(%rip),%rax
mov    (%rax),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1080 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1541 <main+0x381>
mov    0x2b25(%rip),%rax
mov    (%rax),%edi
lea    -0x220(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <write@plt>
cmp    -0x14(%rbp),%eax
je     1506 <main+0x346>
mov    0x2adc(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmpl   $0x1,-0x22c(%rbp)
jne    1521 <main+0x361>
mov    0x2ad6(%rip),%rax
mov    (%rax),%edi
call   10b0 <fsync@plt>
cmpl   $0x1,-0x230(%rbp)
jne    153c <main+0x37c>
mov    0x2abb(%rip),%rax
mov    (%rax),%edi
call   1040 <fdatasync@plt>
jmp    149e <main+0x2de>
cmpl   $0x0,-0x14(%rbp)
jge    156c <main+0x3ac>
mov    0x2a76(%rip),%rax
mov    (%rax),%edi
lea    0xd19(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r13
cmp    $0x2,%edi
jge    1202 <main+0x32>
mov    0x0(%r13),%rsi
lea    0xeb4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12ea <main+0x11a>
mov    %edi,%ebp
xor    %r14d,%r14d
lea    0xfdf(%rip),%r15
lea    0xdeb(%rip),%r12
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
jmp    1241 <main+0x71>
nopw   0x0(%rax,%rax,1)
xor    %ebx,%ebx
lea    0xfa6(%rip),%rdi
call   1050 <puts@plt>
mov    %ebx,%r14d
mov    %ebp,%edi
mov    %r13,%rsi
lea    0xe91(%rip),%rdx
call   10e0 <getopt@plt>
lea    -0x3f(%rax),%ecx
cmp    $0x29,%ecx
ja     1345 <main+0x175>
mov    $0x1,%ebx
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
mov    %r15,%rdi
jmp    *%rax
movl   $0x1,0xc(%rsp)
lea    0xf35(%rip),%rdi
mov    %r14d,%ebx
jmp    1239 <main+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movl   $0x1,0x8(%rsp)
lea    0xee4(%rip),%rdi
mov    %r14d,%ebx
jmp    1239 <main+0x69>
mov    0x2d2d(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10b0 <isprint@plt>
mov    0x2d0d(%rip),%rcx
mov    (%rcx),%edi
test   %eax,%eax
je     131c <main+0x14c>
lea    0xe1c(%rip),%rsi
jmp    1323 <main+0x153>
mov    0x0(%r13),%rsi
lea    0xdd3(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe87(%rip),%rdi
call   1050 <puts@plt>
lea    0xf09(%rip),%rdi
call   1050 <puts@plt>
lea    0xf15(%rip),%rdi
call   1050 <puts@plt>
lea    0xf26(%rip),%rdi
call   1050 <puts@plt>
lea    0xf31(%rip),%rdi
call   1050 <puts@plt>
jmp    1331 <main+0x161>
lea    0xdd8(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0xffffffff,%eax
jne    1374 <main+0x1a4>
mov    0x2c9f(%rip),%r12
mov    (%r12),%edi
mov    0x2c5c(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
xor    %edx,%edx
call   1060 <fcntl@plt>
test   %eax,%eax
jns    137b <main+0x1ab>
lea    0xda1(%rip),%rdi
jmp    13ac <main+0x1dc>
xor    %eax,%eax
call   1030 <abort@plt>
cmp    $0x1,%r14d
jne    138a <main+0x1ba>
mov    0x2c58(%rip),%rcx
mov    (%rcx),%ebp
or     %eax,%ebp
mov    (%r12),%edi
mov    0x2c29(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edx
call   1060 <fcntl@plt>
test   %rax,%rax
jns    13bb <main+0x1eb>
lea    0xd87(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2bee(%rip),%r15
mov    (%r15),%edi
lea    0x10(%rsp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1437 <main+0x267>
lea    0x10(%rsp),%r14
mov    0xc(%rsp),%r13d
mov    0x8(%rsp),%ebx
jmp    1406 <main+0x236>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1437 <main+0x267>
mov    (%r12),%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <write@plt>
cmp    %ebp,%eax
jne    1454 <main+0x284>
cmp    $0x1,%r13d
jne    1427 <main+0x257>
mov    (%r12),%edi
call   10c0 <fsync@plt>
cmp    $0x1,%ebx
jne    13f0 <main+0x220>
mov    (%r12),%edi
call   1040 <fdatasync@plt>
jmp    13f0 <main+0x220>
test   %ebp,%ebp
jns    144d <main+0x27d>
mov    0x2b86(%rip),%rax
mov    (%rax),%edi
lea    0xd15(%rip),%rsi
jmp    1464 <main+0x294>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    0x2b6d(%rip),%rax
mov    (%rax),%edi
lea    0xcef(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"usage: %s -{a|b|c|d} < LARGEFILE_IN > LARGEFILE_OUT \0A\00"
@.str.1 = [25 x i8] c" -a for add O_SYNC flag\0A\00"
@.str.2 = [30 x i8] c" -b for removing O_SYNC flag\0A\00"
@.str.3 = [24 x i8] c" -c for add fsync call\0A\00"
@.str.4 = [50 x i8] c" -d for add fdatasync call (doesnot work in OSX)\0A\00"
@.str.5 = [6 x i8] c"abcdh\00"
@.str.6 = [14 x i8] c"O_SYNC is on\0A\00"
@.str.7 = [15 x i8] c"O_SYNC is off\0A\00"
@.str.8 = [45 x i8] c"O_SYNC is off, writes are followed by fsync\0A\00"
@.str.9 = [49 x i8] c"O_SYNC is off, writes are followed by fdatasync\0A\00"
@.str.10 = [24 x i8] c"Options are a, b, c, d\0A\00"
@optopt = global i32 0
@stderr = global i32 0
@.str.11 = [23 x i8] c"Unknown option `-%c'.\0A\00"
@.str.12 = [24 x i8] c"Unknown option `\\x%x'.\0A\00"
@STDOUT_FILENO = global i32 0
@F_GETFL = global i32 0
@.str.13 = [32 x i8] c"Can't get file descriptor flags\00"
@O_SYNC = global i32 0
@F_SETFL = global i32 0
@.str.14 = [32 x i8] c"Can't set file descriptor flags\00"
@STDIN_FILENO = global i32 0
@.str.15 = [13 x i8] c"write error\0A\00"
@.str.16 = [12 x i8] c"read error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [512 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %24
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %130
24: ; preds = %2
br label %25
25: ; preds = %65, %24
%26 = load i32, i32* %4
%27 = load i8**, i8*** %5
%28 = call i32 @getopt(i32 %26, i8** %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 %28, i32* %7
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %66
30: ; preds = %25
%31 = load i32, i32* %7
switch i32 %31, label %63 [
i32 97, label %32
i32 98, label %34
i32 99, label %36
i32 100, label %38
i32 104, label %40
i32 63, label %50
]
32: ; preds = %30
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %10
br label %65
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %10
br label %65
36: ; preds = %30
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %11
br label %65
38: ; preds = %30
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %12
br label %65
40: ; preds = %30
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %130
50: ; preds = %30
%51 = load i32, i32* @optopt
%52 = call i32 @isprint(i32 %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i32, i32* @stderr
%56 = load i32, i32* @optopt
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0), i32 %56)
br label %62
58: ; preds = %50
%59 = load i32, i32* @stderr
%60 = load i32, i32* @optopt
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %58, %54
store i32 1, i32* %3
br label %130
63: ; preds = %30
%64 = call i32 (...) @abort()
unreachable
65: ; preds = %38, %36, %34, %32
br label %25
66: ; preds = %25
%67 = load i32, i32* @STDOUT_FILENO
%68 = load i32, i32* @F_GETFL
%69 = call i64 @fcntl(i32 %67, i32 %68, i32 0)
%70 = trunc i64 %69 to i32
store i32 %70, i32* %9
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %66
%73 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0))
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %66
%76 = load i32, i32* %10
%77 = icmp eq i32 %76, 1
br i1 %77, label %78, label %82
78: ; preds = %75
%79 = load i32, i32* @O_SYNC
%80 = load i32, i32* %9
%81 = or i32 %80, %79
store i32 %81, i32* %9
br label %82
82: ; preds = %78, %75
%83 = load i32, i32* @STDOUT_FILENO
%84 = load i32, i32* @F_SETFL
%85 = load i32, i32* %9
%86 = call i64 @fcntl(i32 %83, i32 %84, i32 %85)
%87 = icmp slt i64 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %82
%89 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.14, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %82
br label %92
92: ; preds = %120, %91
%93 = load i32, i32* @STDIN_FILENO
%94 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%95 = call i32 @read(i32 %93, i8* %94, i32 512)
store i32 %95, i32* %6
%96 = icmp sgt i32 %95, 0
br i1 %96, label %97, label %121
97: ; preds = %92
%98 = load i32, i32* @STDOUT_FILENO
%99 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%100 = load i32, i32* %6
%101 = call i32 @write(i32 %98, i8* %99, i32 %100)
%102 = load i32, i32* %6
%103 = icmp ne i32 %101, %102
br i1 %103, label %104, label %108
104: ; preds = %97
%105 = load i32, i32* @stderr
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.15, i64 0, i64 0))
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %97
%109 = load i32, i32* %11
%110 = icmp eq i32 %109, 1
br i1 %110, label %111, label %114
111: ; preds = %108
%112 = load i32, i32* @STDOUT_FILENO
%113 = call i32 @fsync(i32 %112)
br label %114
114: ; preds = %111, %108
%115 = load i32, i32* %12
%116 = icmp eq i32 %115, 1
br i1 %116, label %117, label %120
117: ; preds = %114
%118 = load i32, i32* @STDOUT_FILENO
%119 = call i32 @fdatasync(i32 %118)
br label %120
120: ; preds = %117, %114
br label %92
121: ; preds = %92
%122 = load i32, i32* %6
%123 = icmp slt i32 %122, 0
br i1 %123, label %124, label %128
124: ; preds = %121
%125 = load i32, i32* @stderr
%126 = call i32 (i32, i8*, ...) @fprintf(i32 %125, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0))
%127 = call i32 @exit(i32 1)
unreachable
128: ; preds = %121
%129 = call i32 @exit(i32 0)
unreachable
130: ; preds = %62, %40, %15
%131 = load i32, i32* %3
ret i32 %131
}

LLVM IR (-O2):
@.str = [54 x i8] c"usage: %s -{a|b|c|d} < LARGEFILE_IN > LARGEFILE_OUT \0A\00"
@.str.5 = [6 x i8] c"abcdh\00"
@optopt = global i32 0
@stderr = global i32 0
@.str.11 = [23 x i8] c"Unknown option `-%c'.\0A\00"
@.str.12 = [24 x i8] c"Unknown option `\\x%x'.\0A\00"
@STDOUT_FILENO = global i32 0
@F_GETFL = global i32 0
@.str.13 = [32 x i8] c"Can't get file descriptor flags\00"
@O_SYNC = global i32 0
@F_SETFL = global i32 0
@.str.14 = [32 x i8] c"Can't set file descriptor flags\00"
@STDIN_FILENO = global i32 0
@.str.15 = [13 x i8] c"write error\0A\00"
@.str.16 = [12 x i8] c"read error\0A\00"
@str = [23 x i8] c"Options are a, b, c, d\00"
@str.21 = [48 x i8] c"O_SYNC is off, writes are followed by fdatasync\00"
@str.22 = [44 x i8] c"O_SYNC is off, writes are followed by fsync\00"
@str.23 = [14 x i8] c"O_SYNC is off\00"
@str.24 = [13 x i8] c"O_SYNC is on\00"
@str.25 = [24 x i8] c" -a for add O_SYNC flag\00"
@str.26 = [29 x i8] c" -b for removing O_SYNC flag\00"
@str.27 = [23 x i8] c" -c for add fsync call\00"
@str.28 = [49 x i8] c" -d for add fdatasync call (doesnot work in OSX)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.25, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.26, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.27, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.28, i64 0, i64 0))
br label %104
13: ; preds = %2, %40
%14 = phi i32 [ %42, %40 ], [ 0, %2 ]
%15 = phi i32 [ %43, %40 ], [ 0, %2 ]
%16 = phi i32 [ %44, %40 ], [ 0, %2 ]
%17 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
switch i32 %17, label %38 [
i32 -1, label %46
i32 97, label %40
i32 98, label %18
i32 99, label %19
i32 100, label %20
i32 104, label %21
i32 63, label %29
]
18: ; preds = %13
br label %40
19: ; preds = %13
br label %40
20: ; preds = %13
br label %40
21: ; preds = %13
%22 = load i8*, i8** %1
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.25, i64 0, i64 0))
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.26, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.27, i64 0, i64 0))
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.28, i64 0, i64 0))
br label %104
29: ; preds = %13
%30 = load i32, i32* @optopt
%31 = tail call i32 @isprint(i32 %30)
%32 = icmp eq i32 %31, 0
%33 = load i32, i32* @stderr
br i1 %32, label %36, label %34
34: ; preds = %29
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0), i32 %30)
br label %104
36: ; preds = %29
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i32 %30)
br label %104
38: ; preds = %13
%39 = tail call i32 (...) @abort()
unreachable
40: ; preds = %13, %20, %19, %18
%41 = phi i8* [ getelementptr inbounds ([48 x i8], [48 x i8]* @str.21, i64 0, i64 0), %20 ], [ getelementptr inbounds ([44 x i8], [44 x i8]* @str.22, i64 0, i64 0), %19 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.23, i64 0, i64 0), %18 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.24, i64 0, i64 0), %13 ]
%42 = phi i32 [ %14, %20 ], [ %14, %19 ], [ 0, %18 ], [ 1, %13 ]
%43 = phi i32 [ %15, %20 ], [ 1, %19 ], [ %15, %18 ], [ %15, %13 ]
%44 = phi i32 [ 1, %20 ], [ %16, %19 ], [ %16, %18 ], [ %16, %13 ]
%45 = tail call i32 @puts(i8* dereferenceable(1) %41)
br label %13
46: ; preds = %13
%47 = load i32, i32* @STDOUT_FILENO
%48 = load i32, i32* @F_GETFL
%49 = tail call i64 @fcntl(i32 %47, i32 %48, i32 0)
%50 = trunc i64 %49 to i32
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %46
%53 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.13, i64 0, i64 0))
%54 = tail call i32 @exit(i32 1)
unreachable
55: ; preds = %46
%56 = icmp eq i32 %14, 1
%57 = load i32, i32* @O_SYNC
%58 = select i1 %56, i32 %57, i32 0
%59 = or i32 %58, %50
%60 = load i32, i32* @STDOUT_FILENO
%61 = load i32, i32* @F_SETFL
%62 = tail call i64 @fcntl(i32 %60, i32 %61, i32 %59)
%63 = icmp slt i64 %62, 0
br i1 %63, label %71, label %64
64: ; preds = %55
%65 = load i32, i32* @STDIN_FILENO
%66 = call i32 @read(i32 %65, i8* %4, i32 512)
%67 = icmp sgt i32 %66, 0
br i1 %67, label %68, label %95
68: ; preds = %64
%69 = icmp eq i32 %15, 1
%70 = icmp eq i32 %16, 1
br label %74
71: ; preds = %55
%72 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.14, i64 0, i64 0))
%73 = tail call i32 @exit(i32 1)
unreachable
74: ; preds = %68, %91
%75 = phi i32 [ %66, %68 ], [ %93, %91 ]
%76 = load i32, i32* @STDOUT_FILENO
%77 = call i32 @write(i32 %76, i8* %4, i32 %75)
%78 = icmp eq i32 %77, %75
br i1 %78, label %83, label %79
79: ; preds = %74
%80 = load i32, i32* @stderr
%81 = tail call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.15, i64 0, i64 0))
%82 = tail call i32 @exit(i32 1)
unreachable
83: ; preds = %74
br i1 %69, label %84, label %87
84: ; preds = %83
%85 = load i32, i32* @STDOUT_FILENO
%86 = tail call i32 @fsync(i32 %85)
br label %87
87: ; preds = %84, %83
br i1 %70, label %88, label %91
88: ; preds = %87
%89 = load i32, i32* @STDOUT_FILENO
%90 = tail call i32 @fdatasync(i32 %89)
br label %91
91: ; preds = %88, %87
%92 = load i32, i32* @STDIN_FILENO
%93 = call i32 @read(i32 %92, i8* %4, i32 512)
%94 = icmp sgt i32 %93, 0
br i1 %94, label %74, label %95
95: ; preds = %91, %64
%96 = phi i32 [ %66, %64 ], [ %93, %91 ]
%97 = icmp slt i32 %96, 0
br i1 %97, label %98, label %102
98: ; preds = %95
%99 = load i32, i32* @stderr
%100 = tail call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0))
%101 = tail call i32 @exit(i32 1)
unreachable
102: ; preds = %95
%103 = tail call i32 @exit(i32 0)
unreachable
104: ; preds = %34, %36, %21, %6
%105 = phi i32 [ 0, %6 ], [ 0, %21 ], [ 1, %36 ], [ 1, %34 ]
ret i32 %105
}