#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 off_t;

/* Variables and functions */
char EOF;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ do_close(int);
int /*<<< orphan*/ do_lseek(int, int, int /*<<< orphan*/);
int do_open(char *, int);
int /*<<< orphan*/ do_read(int, char *, int);
int do_stat(char *);
int /*<<< orphan*/ do_truncate(int, int);
int /*<<< orphan*/ do_write(int, char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char getopt(int, char **, char *);
scalar_t__ memcmp(char *, char *, int);
char *optarg;
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int fd, count = 0, nc = 1, oc = 2, i;
  char *wrbuf = NULL, *rdbuf = NULL, *extra_buf = NULL, *fname = NULL;
  off_t offset = 0, fsize = 0;
  int _count, _offset;
  char c;
  while ((c = getopt(argc, argv, "f:n:o:")) != EOF) {
    switch (c) {
    case 'f':
      fname = optarg;
      break;
    case 'n':
      nc = atoi(optarg);
      break;
    case 'o':
      oc = atoi(optarg);
      break;
    case '?':
    default:
      fprintf(stderr,
              "Usage: %s -f <filename> -n <count multiplier> -o <offset "
              "multiplier>\n",
              argv[0]);
      exit(1);
    }
  }
  if (nc <= 0 || oc <= 0) {
    fprintf(stderr,
            "Usage: %s -f <filename> -n <count multiplier> -o <offset "
            "multiplier>\n",
            argv[0]);
    exit(1);
  }
  srand(time(NULL));
  _count = (int)(nc * 16384);
  _offset = (int)(oc * 16384);
  count = rand() % _count;
  count = 100;
  printf("Writing to %s %d bytes at offset %ld\n",
         fname ? fname : "/mnt/capfs/testfile", count, offset);
  wrbuf = (char *)calloc(1, count);
  for (i = 0; i < count / sizeof(int); i++) {
    wrbuf[i] = i;
  }
  fd = fname ? do_open(fname, O_RDWR | O_CREAT | O_TRUNC)
             : do_open("/mnt/capfs/testfile", O_RDWR | O_CREAT | O_TRUNC);
  if (fd < 0) {
    printf("do_open - %s\n", strerror(errno));
    exit(1);
  }
  do_lseek(fd, offset, SEEK_SET);
  do_write(fd, wrbuf, count);
  do_close(fd);
  fsize = fname ? do_stat(fname) : do_stat("/mnt/capfs/testfile");
  printf("Size of file before truncate %ld (%ld)\n", fsize, offset + count);
  fd = fname ? do_open(fname, O_RDWR) : do_open("/mnt/capfs/testfile", O_RDWR);
  do_truncate(fd, offset + count / 2);
  fsize = fname ? do_stat(fname) : do_stat("/mnt/capfs/testfile");
  printf("Size of file after truncate %ld (%ld)\n", fsize, offset + count / 2);
  rdbuf = (char *)calloc(fsize, 1);
  do_read(fd, rdbuf, fsize);
  do_close(fd);
  extra_buf = (char *)calloc(1, count / 2);
  if (memcmp(rdbuf + offset, wrbuf, count / 2) == 0) {
    printf("Matches file content\n");
    if (memcmp(rdbuf + offset + count / 2, extra_buf, count / 2) == 0) {
      printf("Rest of file seems to be zeroed out correctly!\n");
    } else {
      printf("Rest of file seems to be NOT zeroed out. This is OK! POSIX "
             "semantics on truncated file is undefined\n");
    }
  } else {
    printf("Does not match\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x2,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd76(%rip),%rdx
call   10d0 <getopt@plt>
mov    %al,-0x59(%rbp)
movsbl %al,%eax
mov    0x2d2c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1360 <main+0x140>
movsbl -0x59(%rbp),%eax
mov    %eax,-0x60(%rbp)
sub    $0x3f,%eax
je     1330 <main+0x110>
jmp    12bc <main+0x9c>
mov    -0x60(%rbp),%eax
sub    $0x66,%eax
je     12ef <main+0xcf>
jmp    12cd <main+0xad>
mov    -0x60(%rbp),%eax
sub    $0x6e,%eax
je     1302 <main+0xe2>
jmp    12de <main+0xbe>
mov    -0x60(%rbp),%eax
sub    $0x6f,%eax
je     1319 <main+0xf9>
jmp    1335 <main+0x115>
mov    0x2cfa(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    135b <main+0x13b>
mov    0x2ce7(%rip),%rax
mov    (%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    135b <main+0x13b>
mov    0x2cd0(%rip),%rax
mov    (%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    135b <main+0x13b>
jmp    1335 <main+0x115>
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xcbb(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
jmp    127c <main+0x5c>
cmpl   $0x0,-0x1c(%rbp)
jle    1374 <main+0x154>
cmpl   $0x0,-0x20(%rbp)
jg     139a <main+0x17a>
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc7c(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    -0x1c(%rbp),%eax
shl    $0xe,%eax
mov    %eax,-0x54(%rbp)
mov    -0x20(%rbp),%eax
shl    $0xe,%eax
mov    %eax,-0x58(%rbp)
mov    $0x0,%al
call   1140 <rand@plt>
cltd
idivl  -0x54(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x64,-0x18(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     13e9 <main+0x1c9>
mov    -0x48(%rbp),%rax
mov    %rax,-0x68(%rbp)
jmp    13f9 <main+0x1d9>
lea    0xc83(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    13f9 <main+0x1d9>
mov    -0x68(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x4c(%rbp),%ecx
lea    0xc43(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%esi
mov    $0x1,%edi
call   1090 <calloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
movslq -0x18(%rbp),%rcx
shr    $0x2,%rcx
cmp    %rcx,%rax
jae    145c <main+0x23c>
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1429 <main+0x209>
cmpq   $0x0,-0x48(%rbp)
je     1493 <main+0x273>
mov    -0x48(%rbp),%rdi
mov    0x2b5e(%rip),%rax
mov    (%rax),%esi
mov    0x2b7d(%rip),%rax
or     (%rax),%esi
mov    0x2b64(%rip),%rax
or     (%rax),%esi
call   1050 <do_open@plt>
mov    %eax,-0x6c(%rbp)
jmp    14bd <main+0x29d>
mov    0x2b36(%rip),%rax
mov    (%rax),%esi
mov    0x2b55(%rip),%rax
or     (%rax),%esi
mov    0x2b3c(%rip),%rax
or     (%rax),%esi
lea    0xbbe(%rip),%rdi
call   1050 <do_open@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    14f6 <main+0x2d6>
mov    0x2adc(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rsi
lea    0xba2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x4c(%rbp),%esi
mov    0x2aa5(%rip),%rax
mov    (%rax),%edx
call   10c0 <do_lseek@plt>
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <do_write@plt>
mov    -0x14(%rbp),%edi
call   10e0 <do_close@plt>
cmpq   $0x0,-0x48(%rbp)
je     153d <main+0x31d>
mov    -0x48(%rbp),%rdi
call   1130 <do_stat@plt>
mov    %eax,-0x70(%rbp)
jmp    154c <main+0x32c>
lea    0xb2f(%rip),%rdi
call   1130 <do_stat@plt>
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%esi
mov    -0x4c(%rbp),%edx
add    -0x18(%rbp),%edx
lea    0xb33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x48(%rbp)
je     158e <main+0x36e>
mov    -0x48(%rbp),%rdi
mov    0x2a51(%rip),%rax
mov    (%rax),%esi
call   1050 <do_open@plt>
mov    %eax,-0x74(%rbp)
jmp    15a6 <main+0x386>
mov    0x2a3b(%rip),%rax
mov    (%rax),%esi
lea    0xad5(%rip),%rdi
call   1050 <do_open@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x4c(%rbp),%esi
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    %eax,%esi
call   1100 <do_truncate@plt>
cmpq   $0x0,-0x48(%rbp)
je     15e0 <main+0x3c0>
mov    -0x48(%rbp),%rdi
call   1130 <do_stat@plt>
mov    %eax,-0x78(%rbp)
jmp    15ef <main+0x3cf>
lea    0xa8c(%rip),%rdi
call   1130 <do_stat@plt>
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%esi
mov    -0x4c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x7c(%rbp),%edx
add    %eax,%edx
lea    0xaa8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x50(%rbp),%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x50(%rbp),%edx
call   1030 <do_read@plt>
mov    -0x14(%rbp),%edi
call   10e0 <do_close@plt>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    $0x1,%edi
call   1090 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
movslq -0x4c(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
jne    16f9 <main+0x4d9>
lea    0xa53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
movslq -0x4c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
add    %rax,%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
jne    16e6 <main+0x4c6>
lea    0xa20(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    16f4 <main+0x4d4>
lea    0xa3d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1707 <main+0x4e7>
lea    0xa8f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xdc6(%rip),%rdx
call   10e0 <getopt@plt>
mov    0x2d72(%rip),%r15
cmp    (%r15),%al
jne    1321 <main+0xf1>
mov    $0x1,%r12d
movl   $0x2,0xc(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
test   %r12d,%r12d
jle    1529 <main+0x2f9>
cmpl   $0x0,0xc(%rsp)
jle    1529 <main+0x2f9>
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
xor    %eax,%eax
call   1150 <rand@plt>
mov    0x10(%rsp),%rbp
test   %rbp,%rbp
lea    0xdd7(%rip),%rsi
cmovne %rbp,%rsi
lea    0xda6(%rip),%rdi
mov    $0x64,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
mov    $0x64,%esi
call   10a0 <calloc@plt>
mov    %rax,%r14
movaps 0xd22(%rip),%xmm0
movups %xmm0,(%rax)
movabs $0x1716151413121110,%rax
15 16 17
mov    %rax,0x10(%r14)
movb   $0x18,0x18(%r14)
mov    0x2cd5(%rip),%r15
mov    0x2cf6(%rip),%rax
mov    (%rax),%esi
or     (%r15),%esi
mov    0x2cda(%rip),%rax
or     (%rax),%esi
test   %rbp,%rbp
je     13ae <main+0x17e>
mov    %rbp,%rdi
jmp    13b5 <main+0x185>
movl   $0x2,0xc(%rsp)
mov    $0x1,%r12d
xor    %ecx,%ecx
mov    %rcx,0x10(%rsp)
mov    0x2cb3(%rip),%r14
lea    0xccc(%rip),%r13
jmp    1371 <main+0x141>
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%rdi
call   1100 <atoi@plt>
mov    %eax,%r12d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   10e0 <getopt@plt>
cmp    (%r15),%al
je     1274 <main+0x44>
movsbl %al,%eax
cmp    $0x6f,%eax
je     13a0 <main+0x170>
cmp    $0x6e,%eax
je     1350 <main+0x120>
cmp    $0x66,%eax
jne    1529 <main+0x2f9>
mov    (%r14),%rax
mov    %rax,0x10(%rsp)
jmp    135b <main+0x12b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%rdi
call   1100 <atoi@plt>
mov    %eax,0xc(%rsp)
jmp    135b <main+0x12b>
lea    0xcce(%rip),%rdi
call   1060 <do_open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     154b <main+0x31b>
mov    0x2bdd(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   10d0 <do_lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1040 <do_write@plt>
mov    %ebx,%edi
call   10f0 <do_close@plt>
test   %rbp,%rbp
je     142d <main+0x1fd>
mov    %rbp,%rdi
call   1140 <do_stat@plt>
lea    0xca5(%rip),%rdi
mov    %eax,%esi
mov    $0x64,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r15),%esi
mov    %rbp,%rdi
call   1060 <do_open@plt>
mov    %eax,%r12d
mov    %eax,%edi
mov    $0x32,%esi
call   1110 <do_truncate@plt>
mov    %rbp,%rdi
jmp    146e <main+0x23e>
lea    0xc4f(%rip),%rbx
mov    %rbx,%rdi
call   1140 <do_stat@plt>
lea    0xc62(%rip),%rdi
mov    %eax,%esi
mov    $0x64,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1060 <do_open@plt>
mov    %eax,%r12d
mov    %eax,%edi
mov    $0x32,%esi
call   1110 <do_truncate@plt>
mov    %rbx,%rdi
call   1140 <do_stat@plt>
mov    %eax,%ebx
lea    0xc51(%rip),%rdi
mov    %eax,%esi
mov    $0x32,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbp
mov    %r12d,%edi
mov    %rax,%rsi
mov    %ebx,%edx
call   1030 <do_read@plt>
mov    %r12d,%edi
call   10f0 <do_close@plt>
mov    $0x1,%edi
mov    $0x32,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x32,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
je     14de <main+0x2ae>
lea    0xc18(%rip),%rdi
jmp    1513 <main+0x2e3>
lea    0xc1e(%rip),%rdi
call   1050 <puts@plt>
add    $0x32,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x32,%edx
call   1090 <memcmp@plt>
test   %rax,%rax
lea    0xc74(%rip),%rax
lea    0xc09(%rip),%rdi
cmove  %rax,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a88(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xadb(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2a5e(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xb37(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"f:n:o:\00"
@EOF = global i8 0
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [70 x i8] c"Usage: %s -f <filename> -n <count multiplier> -o <offset multiplier>\0A\00"
@.str.2 = [38 x i8] c"Writing to %s %d bytes at offset %ld\0A\00"
@.str.3 = [20 x i8] c"/mnt/capfs/testfile\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.4 = [14 x i8] c"do_open - %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.5 = [40 x i8] c"Size of file before truncate %ld (%ld)\0A\00"
@.str.6 = [39 x i8] c"Size of file after truncate %ld (%ld)\0A\00"
@.str.7 = [22 x i8] c"Matches file content\0A\00"
@.str.8 = [48 x i8] c"Rest of file seems to be zeroed out correctly!\0A\00"
@.str.9 = [101 x i8] c"Rest of file seems to be NOT zeroed out. This is OK! POSIX semantics on truncated file is undefined\0A\00"
@.str.10 = [16 x i8] c"Does not match\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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 1, i32* %8
store i32 2, i32* %9
store i8* null, i8** %11
store i8* null, i8** %12
store i8* null, i8** %13
store i8* null, i8** %14
store i32 0, i32* %15
store i32 0, i32* %16
br label %20
20: ; preds = %47, %2
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call signext i8 @getopt(i32 %21, i8** %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8 %23, i8* %19
%24 = sext i8 %23 to i32
%25 = load i8, i8* @EOF
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %24, %26
br i1 %27, label %28, label %48
28: ; preds = %20
%29 = load i8, i8* %19
%30 = sext i8 %29 to i32
switch i32 %30, label %40 [
i32 102, label %31
i32 110, label %33
i32 111, label %36
i32 63, label %39
]
31: ; preds = %28
%32 = load i8*, i8** @optarg
store i8* %32, i8** %14
br label %47
33: ; preds = %28
%34 = load i8*, i8** @optarg
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %8
br label %47
36: ; preds = %28
%37 = load i8*, i8** @optarg
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %9
br label %47
39: ; preds = %28
br label %40
40: ; preds = %28, %39
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %36, %33, %31
br label %20
48: ; preds = %20
%49 = load i32, i32* %8
%50 = icmp sle i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = load i32, i32* %9
%53 = icmp sle i32 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %51, %48
%55 = load i32, i32* @stderr
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 0
%58 = load i8*, i8** %57
%59 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %51
%62 = call i32 @time(i32* null)
%63 = call i32 @srand(i32 %62)
%64 = load i32, i32* %8
%65 = mul nsw i32 %64, 16384
store i32 %65, i32* %17
%66 = load i32, i32* %9
%67 = mul nsw i32 %66, 16384
store i32 %67, i32* %18
%68 = call i32 (...) @rand()
%69 = load i32, i32* %17
%70 = srem i32 %68, %69
store i32 %70, i32* %7
store i32 100, i32* %7
%71 = load i8*, i8** %14
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %75
73: ; preds = %61
%74 = load i8*, i8** %14
br label %76
75: ; preds = %61
br label %76
76: ; preds = %75, %73
%77 = phi i8* [ %74, %73 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %75 ]
%78 = load i32, i32* %7
%79 = load i32, i32* %15
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %77, i32 %78, i32 %79)
%81 = load i32, i32* %7
%82 = call i64 @calloc(i32 1, i32 %81)
%83 = inttoptr i64 %82 to i8*
store i8* %83, i8** %11
store i32 0, i32* %10
br label %84
84: ; preds = %98, %76
%85 = load i32, i32* %10
%86 = sext i32 %85 to i64
%87 = load i32, i32* %7
%88 = sext i32 %87 to i64
%89 = udiv i64 %88, 4
%90 = icmp ult i64 %86, %89
br i1 %90, label %91, label %101
91: ; preds = %84
%92 = load i32, i32* %10
%93 = trunc i32 %92 to i8
%94 = load i8*, i8** %11
%95 = load i32, i32* %10
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8, i8* %94, i64 %96
store i8 %93, i8* %97
br label %98
98: ; preds = %91
%99 = load i32, i32* %10
%100 = add nsw i32 %99, 1
store i32 %100, i32* %10
br label %84
101: ; preds = %84
%102 = load i8*, i8** %14
%103 = icmp ne i8* %102, null
br i1 %103, label %104, label %112
104: ; preds = %101
%105 = load i8*, i8** %14
%106 = load i32, i32* @O_RDWR
%107 = load i32, i32* @O_CREAT
%108 = or i32 %106, %107
%109 = load i32, i32* @O_TRUNC
%110 = or i32 %108, %109
%111 = call i32 @do_open(i8* %105, i32 %110)
br label %119
112: ; preds = %101
%113 = load i32, i32* @O_RDWR
%114 = load i32, i32* @O_CREAT
%115 = or i32 %113, %114
%116 = load i32, i32* @O_TRUNC
%117 = or i32 %115, %116
%118 = call i32 @do_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %117)
br label %119
119: ; preds = %112, %104
%120 = phi i32 [ %111, %104 ], [ %118, %112 ]
store i32 %120, i32* %6
%121 = load i32, i32* %6
%122 = icmp slt i32 %121, 0
br i1 %122, label %123, label %128
123: ; preds = %119
%124 = load i32, i32* @errno
%125 = call i8* @strerror(i32 %124)
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %125)
%127 = call i32 @exit(i32 1)
unreachable
128: ; preds = %119
%129 = load i32, i32* %6
%130 = load i32, i32* %15
%131 = load i32, i32* @SEEK_SET
%132 = call i32 @do_lseek(i32 %129, i32 %130, i32 %131)
%133 = load i32, i32* %6
%134 = load i8*, i8** %11
%135 = load i32, i32* %7
%136 = call i32 @do_write(i32 %133, i8* %134, i32 %135)
%137 = load i32, i32* %6
%138 = call i32 @do_close(i32 %137)
%139 = load i8*, i8** %14
%140 = icmp ne i8* %139, null
br i1 %140, label %141, label %144
141: ; preds = %128
%142 = load i8*, i8** %14
%143 = call i32 @do_stat(i8* %142)
br label %146
144: ; preds = %128
%145 = call i32 @do_stat(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %146
146: ; preds = %144, %141
%147 = phi i32 [ %143, %141 ], [ %145, %144 ]
store i32 %147, i32* %16
%148 = load i32, i32* %16
%149 = load i32, i32* %15
%150 = load i32, i32* %7
%151 = add nsw i32 %149, %150
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %148, i32 %151)
%153 = load i8*, i8** %14
%154 = icmp ne i8* %153, null
br i1 %154, label %155, label %159
155: ; preds = %146
%156 = load i8*, i8** %14
%157 = load i32, i32* @O_RDWR
%158 = call i32 @do_open(i8* %156, i32 %157)
br label %162
159: ; preds = %146
%160 = load i32, i32* @O_RDWR
%161 = call i32 @do_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %160)
br label %162
162: ; preds = %159, %155
%163 = phi i32 [ %158, %155 ], [ %161, %159 ]
store i32 %163, i32* %6
%164 = load i32, i32* %6
%165 = load i32, i32* %15
%166 = load i32, i32* %7
%167 = sdiv i32 %166, 2
%168 = add nsw i32 %165, %167
%169 = call i32 @do_truncate(i32 %164, i32 %168)
%170 = load i8*, i8** %14
%171 = icmp ne i8* %170, null
br i1 %171, label %172, label %175
172: ; preds = %162
%173 = load i8*, i8** %14
%174 = call i32 @do_stat(i8* %173)
br label %177
175: ; preds = %162
%176 = call i32 @do_stat(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %177
177: ; preds = %175, %172
%178 = phi i32 [ %174, %172 ], [ %176, %175 ]
store i32 %178, i32* %16
%179 = load i32, i32* %16
%180 = load i32, i32* %15
%181 = load i32, i32* %7
%182 = sdiv i32 %181, 2
%183 = add nsw i32 %180, %182
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i32 %179, i32 %183)
%185 = load i32, i32* %16
%186 = call i64 @calloc(i32 %185, i32 1)
%187 = inttoptr i64 %186 to i8*
store i8* %187, i8** %12
%188 = load i32, i32* %6
%189 = load i8*, i8** %12
%190 = load i32, i32* %16
%191 = call i32 @do_read(i32 %188, i8* %189, i32 %190)
%192 = load i32, i32* %6
%193 = call i32 @do_close(i32 %192)
%194 = load i32, i32* %7
%195 = sdiv i32 %194, 2
%196 = call i64 @calloc(i32 1, i32 %195)
%197 = inttoptr i64 %196 to i8*
store i8* %197, i8** %13
%198 = load i8*, i8** %12
%199 = load i32, i32* %15
%200 = sext i32 %199 to i64
%201 = getelementptr inbounds i8, i8* %198, i64 %200
%202 = load i8*, i8** %11
%203 = load i32, i32* %7
%204 = sdiv i32 %203, 2
%205 = call i64 @memcmp(i8* %201, i8* %202, i32 %204)
%206 = icmp eq i64 %205, 0
br i1 %206, label %207, label %227
207: ; preds = %177
%208 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%209 = load i8*, i8** %12
%210 = load i32, i32* %15
%211 = sext i32 %210 to i64
%212 = getelementptr inbounds i8, i8* %209, i64 %211
%213 = load i32, i32* %7
%214 = sdiv i32 %213, 2
%215 = sext i32 %214 to i64
%216 = getelementptr inbounds i8, i8* %212, i64 %215
%217 = load i8*, i8** %13
%218 = load i32, i32* %7
%219 = sdiv i32 %218, 2
%220 = call i64 @memcmp(i8* %216, i8* %217, i32 %219)
%221 = icmp eq i64 %220, 0
br i1 %221, label %222, label %224
222: ; preds = %207
%223 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.8, i64 0, i64 0))
br label %226
224: ; preds = %207
%225 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.9, i64 0, i64 0))
br label %226
226: ; preds = %224, %222
br label %229
227: ; preds = %177
%228 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %229
229: ; preds = %227, %226
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"f:n:o:\00"
@EOF = global i8 0
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [70 x i8] c"Usage: %s -f <filename> -n <count multiplier> -o <offset multiplier>\0A\00"
@.str.2 = [38 x i8] c"Writing to %s %d bytes at offset %ld\0A\00"
@.str.3 = [20 x i8] c"/mnt/capfs/testfile\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.4 = [14 x i8] c"do_open - %s\0A\00"
@errno = global i32 0
@SEEK_SET = global i32 0
@.str.5 = [40 x i8] c"Size of file before truncate %ld (%ld)\0A\00"
@.str.6 = [39 x i8] c"Size of file after truncate %ld (%ld)\0A\00"
@str = [15 x i8] c"Does not match\00"
@str.11 = [21 x i8] c"Matches file content\00"
@str.12 = [100 x i8] c"Rest of file seems to be NOT zeroed out. This is OK! POSIX semantics on truncated file is undefined\00"
@str.13 = [47 x i8] c"Rest of file seems to be zeroed out correctly!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %3, %4
br i1 %5, label %32, label %6
6: ; preds = %2, %25
%7 = phi i8 [ %29, %25 ], [ %3, %2 ]
%8 = phi i32 [ %28, %25 ], [ 1, %2 ]
%9 = phi i32 [ %27, %25 ], [ 2, %2 ]
%10 = phi i8* [ %26, %25 ], [ null, %2 ]
%11 = sext i8 %7 to i32
switch i32 %11, label %20 [
i32 102, label %12
i32 110, label %14
i32 111, label %17
]
12: ; preds = %6
%13 = load i8*, i8** @optarg
br label %25
14: ; preds = %6
%15 = load i8*, i8** @optarg
%16 = tail call i32 @atoi(i8* %15)
br label %25
17: ; preds = %6
%18 = load i8*, i8** @optarg
%19 = tail call i32 @atoi(i8* %18)
br label %25
20: ; preds = %6
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %1
%23 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17, %14, %12
%26 = phi i8* [ %10, %17 ], [ %10, %14 ], [ %13, %12 ]
%27 = phi i32 [ %19, %17 ], [ %9, %14 ], [ %9, %12 ]
%28 = phi i32 [ %8, %17 ], [ %16, %14 ], [ %8, %12 ]
%29 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%30 = load i8, i8* @EOF
%31 = icmp eq i8 %29, %30
br i1 %31, label %32, label %6
32: ; preds = %25, %2
%33 = phi i8* [ null, %2 ], [ %26, %25 ]
%34 = phi i32 [ 2, %2 ], [ %27, %25 ]
%35 = phi i32 [ 1, %2 ], [ %28, %25 ]
%36 = icmp slt i32 %35, 1
%37 = icmp slt i32 %34, 1
%38 = select i1 %36, i1 true, i1 %37
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %1
%42 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %32
%45 = tail call i32 @time(i32* null)
%46 = tail call i32 @srand(i32 %45)
%47 = tail call i32 (...) @rand()
%48 = icmp eq i8* %33, null
%49 = select i1 %48, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %33
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %49, i32 100, i32 0)
%51 = tail call i64 @calloc(i32 1, i32 100)
%52 = inttoptr i64 %51 to i8*
%53 = inttoptr i64 %51 to <16 x i8>*
store <16 x i8> <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, <16 x i8>* %53
%54 = getelementptr inbounds i8, i8* %52, i64 16
store i8 16, i8* %54
%55 = getelementptr inbounds i8, i8* %52, i64 17
store i8 17, i8* %55
%56 = getelementptr inbounds i8, i8* %52, i64 18
store i8 18, i8* %56
%57 = getelementptr inbounds i8, i8* %52, i64 19
store i8 19, i8* %57
%58 = getelementptr inbounds i8, i8* %52, i64 20
store i8 20, i8* %58
%59 = getelementptr inbounds i8, i8* %52, i64 21
store i8 21, i8* %59
%60 = getelementptr inbounds i8, i8* %52, i64 22
store i8 22, i8* %60
%61 = getelementptr inbounds i8, i8* %52, i64 23
store i8 23, i8* %61
%62 = getelementptr inbounds i8, i8* %52, i64 24
store i8 24, i8* %62
%63 = load i32, i32* @O_RDWR
%64 = load i32, i32* @O_CREAT
%65 = or i32 %64, %63
%66 = load i32, i32* @O_TRUNC
%67 = or i32 %65, %66
br i1 %48, label %70, label %68
68: ; preds = %44
%69 = tail call i32 @do_open(i8* %33, i32 %67)
br label %72
70: ; preds = %44
%71 = tail call i32 @do_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %67)
br label %72
72: ; preds = %70, %68
%73 = phi i32 [ %69, %68 ], [ %71, %70 ]
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %80
75: ; preds = %72
%76 = load i32, i32* @errno
%77 = tail call i8* @strerror(i32 %76)
%78 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %77)
%79 = tail call i32 @exit(i32 1)
unreachable
80: ; preds = %72
%81 = load i32, i32* @SEEK_SET
%82 = tail call i32 @do_lseek(i32 %73, i32 0, i32 %81)
%83 = tail call i32 @do_write(i32 %73, i8* %52, i32 100)
%84 = tail call i32 @do_close(i32 %73)
br i1 %48, label %92, label %85
85: ; preds = %80
%86 = tail call i32 @do_stat(i8* %33)
%87 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %86, i32 100)
%88 = load i32, i32* @O_RDWR
%89 = tail call i32 @do_open(i8* %33, i32 %88)
%90 = tail call i32 @do_truncate(i32 %89, i32 50)
%91 = tail call i32 @do_stat(i8* %33)
br label %99
92: ; preds = %80
%93 = tail call i32 @do_stat(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%94 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %93, i32 100)
%95 = load i32, i32* @O_RDWR
%96 = tail call i32 @do_open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %95)
%97 = tail call i32 @do_truncate(i32 %96, i32 50)
%98 = tail call i32 @do_stat(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %99
99: ; preds = %92, %85
%100 = phi i32 [ %89, %85 ], [ %96, %92 ]
%101 = phi i32 [ %91, %85 ], [ %98, %92 ]
%102 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i32 %101, i32 50)
%103 = tail call i64 @calloc(i32 %101, i32 1)
%104 = inttoptr i64 %103 to i8*
%105 = tail call i32 @do_read(i32 %100, i8* %104, i32 %101)
%106 = tail call i32 @do_close(i32 %100)
%107 = tail call i64 @calloc(i32 1, i32 50)
%108 = tail call i64 @memcmp(i8* %104, i8* %52, i32 50)
%109 = icmp eq i64 %108, 0
br i1 %109, label %110, label %117
110: ; preds = %99
%111 = inttoptr i64 %107 to i8*
%112 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
%113 = getelementptr inbounds i8, i8* %104, i64 50
%114 = tail call i64 @memcmp(i8* %113, i8* %111, i32 50)
%115 = icmp eq i64 %114, 0
%116 = select i1 %115, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @str.13, i64 0, i64 0), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @str.12, i64 0, i64 0)
br label %117
117: ; preds = %99, %110
%118 = phi i8* [ %116, %110 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0), %99 ]
%119 = tail call i32 @puts(i8* dereferenceable(1) %118)
ret i32 0
}