#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 dummy;
};

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ MCWriteConst(int, int, int);
int O_CREAT;
int O_RDONLY;
int O_RDWR;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getpid();
scalar_t__ lseek(int, long, int /*<<< orphan*/);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int);
void writeIfChanged(char *fname, int lang, int orConsts) {
  char tmpname[32];
  char buf[BUFSIZ], tbuf[BUFSIZ], *cptr, *tptr;
  int fd, tfd;
  int diff = 0;
  int c, len, tlen;
  struct stat sbuf;
  if (stat(fname, &sbuf)) {
    if ((fd = open(fname, O_WRONLY | O_CREAT, 0666)) < 0) {
      fprintf(stderr, "gencat: Unable to create header file %s.\n", fname);
      exit(1);
    }
    MCWriteConst(fd, lang, orConsts);
    close(fd);
    return;
  }
  sprintf(tmpname, "/tmp/gencat.%d", (int)getpid());
  if ((tfd = open(tmpname, O_RDWR | O_CREAT, 0666)) < 0) {
    fprintf(stderr, "gencat: Unable to open temporary file: %s\n", tmpname);
    exit(1);
  }
  unlink(tmpname);
  MCWriteConst(tfd, lang, orConsts);
  if ((fd = open(fname, O_RDONLY)) < 0) {
    fprintf(stderr, "gencat: Unable to read header file: %s\n", fname);
    exit(1);
  }
  if (lseek(tfd, 0L, SEEK_SET) < 0) {
    fprintf(stderr, "gencat: Unable to seek in tempfile: %s\n", tmpname);
    exit(1);
  }
  while ((tlen = read(tfd, tbuf, BUFSIZ)) > 0) {
    if ((len = read(fd, buf, BUFSIZ)) != tlen) {
      diff = ~0;
      goto done;
    }
    for (cptr = buf, tptr = tbuf; cptr < buf + len; ++cptr, ++tptr) {
      if (*tptr != *cptr) {
        diff = ~0;
        goto done;
      }
    }
  }
done:
  if (diff) {
    if (lseek(tfd, 0L, SEEK_SET) < 0) {
      fprintf(stderr, "gencat: Unable to seek in tempfile: %s\n", tmpname);
      exit(1);
    }
    close(fd);
    if ((fd = open(fname, O_WRONLY | O_TRUNC)) < 0) {
      fprintf(stderr, "gencat: Unable to truncate header file: %s\n", fname);
      exit(1);
    }
    while ((len = read(tfd, buf, BUFSIZ)) > 0) {
      if (write(fd, buf, len) != len) {
        fprintf(stderr, "gencat: Error writing to header file: %s\n", fname);
      }
    }
  }
  close(fd);
  close(tfd);
}


x86 assembly (clang, -O0):
<writeIfChanged>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x90(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x40(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x78(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
je     12b6 <writeIfChanged+0xf6>
mov    -0x8(%rbp),%rdi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
mov    0x2da1(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
jge    1294 <writeIfChanged+0xd4>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd7b(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x5c(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10b0 <MCWriteConst@plt>
mov    -0x5c(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x7c(%rbp)
jmp    15c0 <writeIfChanged+0x400>
lea    -0x30(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x98(%rbp),%rdi
mov    %eax,%edx
lea    0xd52(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2cf0(%rip),%rax
mov    (%rax),%esi
mov    0x2d07(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x60(%rbp)
cmp    $0x0,%eax
jge    132e <writeIfChanged+0x16e>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xd1a(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x30(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x60(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10b0 <MCWriteConst@plt>
mov    -0x8(%rbp),%rdi
mov    0x2c80(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
jge    1388 <writeIfChanged+0x1c8>
mov    0x2c54(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xceb(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x60(%rbp),%edi
mov    0x2c1e(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <lseek@plt>
cmp    $0x0,%rax
jge    13ca <writeIfChanged+0x20a>
mov    0x2c12(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xcd1(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    13cf <writeIfChanged+0x20f>
mov    -0x88(%rbp),%rsi
mov    -0x60(%rbp),%edi
mov    0x2bd8(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    %eax,-0x70(%rbp)
cmp    $0x0,%eax
jle    149d <writeIfChanged+0x2dd>
mov    -0x90(%rbp),%rsi
mov    -0x5c(%rbp),%edi
mov    0x2bb4(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    %eax,-0x6c(%rbp)
cmp    -0x70(%rbp),%eax
je     1423 <writeIfChanged+0x263>
movl   $0xffffffff,-0x64(%rbp)
jmp    14a2 <writeIfChanged+0x2e2>
mov    -0x88(%rbp),%rax
mov    -0x90(%rbp),%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,-0x58(%rbp)
mov    -0x90(%rbp),%rcx
mov    -0x50(%rbp),%rax
movslq -0x6c(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    1498 <writeIfChanged+0x2d8>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
mov    -0x50(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1476 <writeIfChanged+0x2b6>
movl   $0xffffffff,-0x64(%rbp)
jmp    14a2 <writeIfChanged+0x2e2>
jmp    147b <writeIfChanged+0x2bb>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1439 <writeIfChanged+0x279>
jmp    13cf <writeIfChanged+0x20f>
jmp    14a2 <writeIfChanged+0x2e2>
cmpl   $0x0,-0x64(%rbp)
je     15a9 <writeIfChanged+0x3e9>
mov    -0x60(%rbp),%edi
mov    0x2afa(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <lseek@plt>
cmp    $0x0,%rax
jge    14ee <writeIfChanged+0x32e>
mov    0x2aee(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xbad(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x5c(%rbp),%edi
call   1070 <close@plt>
mov    -0x8(%rbp),%rdi
mov    0x2a9f(%rip),%rax
mov    (%rax),%esi
mov    0x2ae6(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x5c(%rbp)
cmp    $0x0,%eax
jge    1542 <writeIfChanged+0x382>
mov    0x2a9a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xb81(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    1547 <writeIfChanged+0x387>
mov    -0x90(%rbp),%rsi
mov    -0x60(%rbp),%edi
mov    0x2a60(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    %eax,-0x6c(%rbp)
cmp    $0x0,%eax
jle    15a4 <writeIfChanged+0x3e4>
mov    -0x90(%rbp),%rsi
mov    -0x5c(%rbp),%edi
mov    -0x6c(%rbp),%edx
call   1040 <write@plt>
cmp    -0x6c(%rbp),%eax
je     159f <writeIfChanged+0x3df>
mov    0x2a33(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xb46(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1547 <writeIfChanged+0x387>
jmp    15a9 <writeIfChanged+0x3e9>
mov    -0x5c(%rbp),%edi
call   1070 <close@plt>
mov    -0x60(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x7c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeIfChanged>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,-0x2c(%rbp)
mov    %esi,-0x3c(%rbp)
mov    %rdi,%rbx
mov    %rsp,%r14
mov    0x2dd4(%rip),%rcx
mov    (%rcx),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    (%rcx),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    -0x50(%rbp),%rsi
call   10a0 <stat@plt>
test   %rax,%rax
je     1256 <writeIfChanged+0x96>
mov    0x2d81(%rip),%rax
mov    0x2dd2(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     1462 <writeIfChanged+0x2a2>
mov    %eax,%r15d
mov    %eax,%edi
mov    -0x3c(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   10b0 <MCWriteConst@plt>
jmp    1448 <writeIfChanged+0x288>
mov    %rbx,-0x38(%rbp)
mov    %r14,-0x48(%rbp)
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xdbe(%rip),%rsi
lea    -0x70(%rbp),%r14
mov    %r14,%rdi
mov    %eax,%edx
call   10d0 <sprintf@plt>
mov    0x2d57(%rip),%rax
mov    0x2d70(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     1489 <writeIfChanged+0x2c9>
mov    %eax,%r15d
lea    -0x70(%rbp),%rdi
call   1030 <unlink@plt>
mov    %r15d,%edi
mov    -0x3c(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   10b0 <MCWriteConst@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
call   10c0 <open@plt>
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
js     149f <writeIfChanged+0x2df>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
test   %rax,%rax
js     1477 <writeIfChanged+0x2b7>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %r13,%rsi
call   1080 <read@plt>
test   %eax,%eax
jle    1378 <writeIfChanged+0x1b8>
mov    %eax,%r14d
mov    0x2c9e(%rip),%rbx
mov    (%rbx),%edx
mov    -0x2c(%rbp),%edi
mov    %r12,%rsi
call   1080 <read@plt>
cmp    %r14d,%eax
jne    1381 <writeIfChanged+0x1c1>
mov    %r14d,%eax
add    %r12,%rax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x0(%r13,%rcx,1),%edx
cmp    (%r12,%rcx,1),%dl
jne    1381 <writeIfChanged+0x1c1>
lea    (%r12,%rcx,1),%rdx
add    $0x1,%rdx
add    $0x1,%rcx
cmp    %rax,%rdx
jb     1340 <writeIfChanged+0x180>
mov    0x2c54(%rip),%rbx
mov    (%rbx),%edx
mov    %r15d,%edi
mov    %r13,%rsi
call   1080 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
jg     131a <writeIfChanged+0x15a>
mov    -0x48(%rbp),%r14
jmp    1440 <writeIfChanged+0x280>
mov    0x2c28(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
test   %rax,%rax
js     1477 <writeIfChanged+0x2b7>
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
mov    0x2bf4(%rip),%rax
mov    0x2c3d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
call   10c0 <open@plt>
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
mov    -0x48(%rbp),%r14
js     14b1 <writeIfChanged+0x2f1>
mov    0x2be0(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %r12,%rsi
call   1080 <read@plt>
test   %eax,%eax
jle    1440 <writeIfChanged+0x280>
mov    %eax,%ebx
mov    0x2bce(%rip),%r14
lea    0xce7(%rip),%r13
jmp    141e <writeIfChanged+0x25e>
nopl   0x0(%rax,%rax,1)
mov    0x2bb1(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %r12,%rsi
call   1080 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1378 <writeIfChanged+0x1b8>
mov    -0x2c(%rbp),%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
cmp    %ebx,%eax
je     1400 <writeIfChanged+0x240>
mov    (%r14),%edi
mov    %r13,%rsi
mov    -0x38(%rbp),%rdx
call   1090 <fprintf@plt>
jmp    1400 <writeIfChanged+0x240>
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b57(%rip),%rax
mov    (%rax),%edi
lea    0xb8e(%rip),%rsi
mov    %rbx,%rdx
jmp    14c5 <writeIfChanged+0x305>
mov    0x2b42(%rip),%rax
mov    (%rax),%edi
lea    0xc05(%rip),%rsi
jmp    1499 <writeIfChanged+0x2d9>
mov    0x2b30(%rip),%rax
mov    (%rax),%edi
lea    0xba0(%rip),%rsi
lea    -0x70(%rbp),%rdx
jmp    14c5 <writeIfChanged+0x305>
mov    0x2b1a(%rip),%rax
mov    (%rax),%edi
lea    0xbb5(%rip),%rsi
jmp    14c1 <writeIfChanged+0x301>
mov    0x2b08(%rip),%rax
mov    (%rax),%edi
lea    0xbf3(%rip),%rsi
mov    -0x38(%rbp),%rdx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@BUFSIZ = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"gencat: Unable to create header file %s.\0A\00"
@.str.1 = [15 x i8] c"/tmp/gencat.%d\00"
@O_RDWR = global i32 0
@.str.2 = [43 x i8] c"gencat: Unable to open temporary file: %s\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [40 x i8] c"gencat: Unable to read header file: %s\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [40 x i8] c"gencat: Unable to seek in tempfile: %s\0A\00"
@O_TRUNC = global i32 0
@.str.5 = [44 x i8] c"gencat: Unable to truncate header file: %s\0A\00"
@.str.6 = [42 x i8] c"gencat: Error writing to header file: %s\0A\00"
define void @writeIfChanged(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [32 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca %struct.stat
%20 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%21 = load i32, i32* @BUFSIZ
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %8
%24 = alloca i8, i64 %22
store i64 %22, i64* %9
%25 = load i32, i32* @BUFSIZ
%26 = zext i32 %25 to i64
%27 = alloca i8, i64 %26
store i64 %26, i64* %10
store i32 0, i32* %15
%28 = load i8*, i8** %4
%29 = call i64 @stat(i8* %28, %struct.stat* %19)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %50
31: ; preds = %3
%32 = load i8*, i8** %4
%33 = load i32, i32* @O_WRONLY
%34 = load i32, i32* @O_CREAT
%35 = or i32 %33, %34
%36 = call i32 (i8*, i32, ...) @open(i8* %32, i32 %35, i32 438)
store i32 %36, i32* %13
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %4
%41 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %31
%44 = load i32, i32* %13
%45 = load i32, i32* %5
%46 = load i32, i32* %6
%47 = call i32 @MCWriteConst(i32 %44, i32 %45, i32 %46)
%48 = load i32, i32* %13
%49 = call i32 @close(i32 %48)
store i32 1, i32* %20
br label %179
50: ; preds = %3
%51 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%52 = call i64 (...) @getpid()
%53 = trunc i64 %52 to i32
%54 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%56 = load i32, i32* @O_RDWR
%57 = load i32, i32* @O_CREAT
%58 = or i32 %56, %57
%59 = call i32 (i8*, i32, ...) @open(i8* %55, i32 %58, i32 438)
store i32 %59, i32* %14
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %50
%62 = load i32, i32* @stderr
%63 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%64 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %50
%67 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%68 = call i32 @unlink(i8* %67)
%69 = load i32, i32* %14
%70 = load i32, i32* %5
%71 = load i32, i32* %6
%72 = call i32 @MCWriteConst(i32 %69, i32 %70, i32 %71)
%73 = load i8*, i8** %4
%74 = load i32, i32* @O_RDONLY
%75 = call i32 (i8*, i32, ...) @open(i8* %73, i32 %74)
store i32 %75, i32* %13
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %82
77: ; preds = %66
%78 = load i32, i32* @stderr
%79 = load i8*, i8** %4
%80 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %79)
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %66
%83 = load i32, i32* %14
%84 = load i32, i32* @SEEK_SET
%85 = call i64 @lseek(i32 %83, i64 0, i32 %84)
%86 = icmp slt i64 %85, 0
br i1 %86, label %87, label %92
87: ; preds = %82
%88 = load i32, i32* @stderr
%89 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%90 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %89)
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %82
br label %93
93: ; preds = %127, %92
%94 = load i32, i32* %14
%95 = load i32, i32* @BUFSIZ
%96 = call i32 @read(i32 %94, i8* %27, i32 %95)
store i32 %96, i32* %18
%97 = icmp sgt i32 %96, 0
br i1 %97, label %98, label %128
98: ; preds = %93
%99 = load i32, i32* %13
%100 = load i32, i32* @BUFSIZ
%101 = call i32 @read(i32 %99, i8* %24, i32 %100)
store i32 %101, i32* %17
%102 = load i32, i32* %18
%103 = icmp ne i32 %101, %102
br i1 %103, label %104, label %105
104: ; preds = %98
store i32 -1, i32* %15
br label %129
105: ; preds = %98
store i8* %24, i8** %11
store i8* %27, i8** %12
br label %106
106: ; preds = %122, %105
%107 = load i8*, i8** %11
%108 = load i32, i32* %17
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %24, i64 %109
%111 = icmp ult i8* %107, %110
br i1 %111, label %112, label %127
112: ; preds = %106
%113 = load i8*, i8** %12
%114 = load i8, i8* %113
%115 = sext i8 %114 to i32
%116 = load i8*, i8** %11
%117 = load i8, i8* %116
%118 = sext i8 %117 to i32
%119 = icmp ne i32 %115, %118
br i1 %119, label %120, label %121
120: ; preds = %112
store i32 -1, i32* %15
br label %129
121: ; preds = %112
br label %122
122: ; preds = %121
%123 = load i8*, i8** %11
%124 = getelementptr inbounds i8, i8* %123, i32 1
store i8* %124, i8** %11
%125 = load i8*, i8** %12
%126 = getelementptr inbounds i8, i8* %125, i32 1
store i8* %126, i8** %12
br label %106
127: ; preds = %106
br label %93
128: ; preds = %93
br label %129
129: ; preds = %128, %120, %104
%130 = load i32, i32* %15
%131 = icmp ne i32 %130, 0
br i1 %131, label %132, label %174
132: ; preds = %129
%133 = load i32, i32* %14
%134 = load i32, i32* @SEEK_SET
%135 = call i64 @lseek(i32 %133, i64 0, i32 %134)
%136 = icmp slt i64 %135, 0
br i1 %136, label %137, label %142
137: ; preds = %132
%138 = load i32, i32* @stderr
%139 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%140 = call i32 @fprintf(i32 %138, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %139)
%141 = call i32 @exit(i32 1)
unreachable
142: ; preds = %132
%143 = load i32, i32* %13
%144 = call i32 @close(i32 %143)
%145 = load i8*, i8** %4
%146 = load i32, i32* @O_WRONLY
%147 = load i32, i32* @O_TRUNC
%148 = or i32 %146, %147
%149 = call i32 (i8*, i32, ...) @open(i8* %145, i32 %148)
store i32 %149, i32* %13
%150 = icmp slt i32 %149, 0
br i1 %150, label %151, label %156
151: ; preds = %142
%152 = load i32, i32* @stderr
%153 = load i8*, i8** %4
%154 = call i32 @fprintf(i32 %152, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i8* %153)
%155 = call i32 @exit(i32 1)
unreachable
156: ; preds = %142
br label %157
157: ; preds = %172, %156
%158 = load i32, i32* %14
%159 = load i32, i32* @BUFSIZ
%160 = call i32 @read(i32 %158, i8* %24, i32 %159)
store i32 %160, i32* %17
%161 = icmp sgt i32 %160, 0
br i1 %161, label %162, label %173
162: ; preds = %157
%163 = load i32, i32* %13
%164 = load i32, i32* %17
%165 = call i32 @write(i32 %163, i8* %24, i32 %164)
%166 = load i32, i32* %17
%167 = icmp ne i32 %165, %166
br i1 %167, label %168, label %172
168: ; preds = %162
%169 = load i32, i32* @stderr
%170 = load i8*, i8** %4
%171 = call i32 @fprintf(i32 %169, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %170)
br label %172
172: ; preds = %168, %162
br label %157
173: ; preds = %157
br label %174
174: ; preds = %173, %129
%175 = load i32, i32* %13
%176 = call i32 @close(i32 %175)
%177 = load i32, i32* %14
%178 = call i32 @close(i32 %177)
store i32 0, i32* %20
br label %179
179: ; preds = %174, %43
%180 = load i8*, i8** %8
%181 = load i32, i32* %20
switch i32 %181, label %183 [
i32 0, label %182
i32 1, label %182
]
182: ; preds = %179, %179
ret void
183: ; preds = %179
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@BUFSIZ = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [42 x i8] c"gencat: Unable to create header file %s.\0A\00"
@.str.1 = [15 x i8] c"/tmp/gencat.%d\00"
@O_RDWR = global i32 0
@.str.2 = [43 x i8] c"gencat: Unable to open temporary file: %s\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [40 x i8] c"gencat: Unable to read header file: %s\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [40 x i8] c"gencat: Unable to seek in tempfile: %s\0A\00"
@O_TRUNC = global i32 0
@.str.5 = [44 x i8] c"gencat: Unable to truncate header file: %s\0A\00"
@.str.6 = [42 x i8] c"gencat: Error writing to header file: %s\0A\00"
define void @writeIfChanged(i8* %0, i32 %1, i32 %2) {
%4 = alloca [32 x i8]
%5 = alloca %struct.stat
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = alloca i8, i64 %12
%14 = bitcast %struct.stat* %5 to i8*
%15 = call i64 @stat(i8* %0, %struct.stat* %5)
%16 = icmp eq i64 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %3
%18 = load i32, i32* @O_WRONLY
%19 = load i32, i32* @O_CREAT
%20 = or i32 %19, %18
%21 = call i32 (i8*, i32, ...) @open(i8* %0, i32 %20, i32 438)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %0)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17
%28 = call i32 @MCWriteConst(i32 %21, i32 %1, i32 %2)
br label %123
29: ; preds = %3
%30 = call i64 (...) @getpid()
%31 = trunc i64 %30 to i32
%32 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i32, i32* @O_RDWR
%34 = load i32, i32* @O_CREAT
%35 = or i32 %34, %33
%36 = call i32 (i8*, i32, ...) @open(i8* %6, i32 %35, i32 438)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %29
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %29
%43 = call i32 @unlink(i8* %6)
%44 = call i32 @MCWriteConst(i32 %36, i32 %1, i32 %2)
%45 = load i32, i32* @O_RDONLY
%46 = call i32 (i8*, i32, ...) @open(i8* %0, i32 %45)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %42
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %42
%53 = load i32, i32* @SEEK_SET
%54 = call i64 @lseek(i32 %36, i64 0, i32 %53)
%55 = icmp slt i64 %54, 0
br i1 %55, label %60, label %56
56: ; preds = %52
%57 = load i32, i32* @BUFSIZ
%58 = call i32 @read(i32 %36, i8* %13, i32 %57)
%59 = icmp sgt i32 %58, 0
br i1 %59, label %68, label %120
60: ; preds = %52
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %82
%65 = load i32, i32* @BUFSIZ
%66 = call i32 @read(i32 %36, i8* %13, i32 %65)
%67 = icmp sgt i32 %66, 0
br i1 %67, label %68, label %120
68: ; preds = %56, %64
%69 = phi i32 [ %66, %64 ], [ %58, %56 ]
%70 = load i32, i32* @BUFSIZ
%71 = call i32 @read(i32 %46, i8* %10, i32 %70)
%72 = icmp eq i32 %71, %69
br i1 %72, label %73, label %86
73: ; preds = %68
%74 = zext i32 %69 to i64
%75 = getelementptr inbounds i8, i8* %10, i64 %74
br label %76
76: ; preds = %73, %82
%77 = phi i8* [ %83, %82 ], [ %10, %73 ]
%78 = phi i8* [ %84, %82 ], [ %13, %73 ]
%79 = load i8, i8* %78
%80 = load i8, i8* %77
%81 = icmp eq i8 %79, %80
br i1 %81, label %82, label %86
82: ; preds = %76
%83 = getelementptr inbounds i8, i8* %77, i64 1
%84 = getelementptr inbounds i8, i8* %78, i64 1
%85 = icmp ult i8* %83, %75
br i1 %85, label %76, label %64
86: ; preds = %68, %76
%87 = load i32, i32* @SEEK_SET
%88 = call i64 @lseek(i32 %36, i64 0, i32 %87)
%89 = icmp slt i64 %88, 0
br i1 %89, label %90, label %94
90: ; preds = %86
%91 = load i32, i32* @stderr
%92 = call i32 @fprintf(i32 %91, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %86
%95 = call i32 @close(i32 %46)
%96 = load i32, i32* @O_WRONLY
%97 = load i32, i32* @O_TRUNC
%98 = or i32 %97, %96
%99 = call i32 (i8*, i32, ...) @open(i8* %0, i32 %98)
%100 = icmp slt i32 %99, 0
br i1 %100, label %105, label %101
101: ; preds = %94
%102 = load i32, i32* @BUFSIZ
%103 = call i32 @read(i32 %36, i8* %10, i32 %102)
%104 = icmp sgt i32 %103, 0
br i1 %104, label %109, label %120
105: ; preds = %94
%106 = load i32, i32* @stderr
%107 = call i32 @fprintf(i32 %106, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %101, %116
%110 = phi i32 [ %118, %116 ], [ %103, %101 ]
%111 = call i32 @write(i32 %99, i8* %10, i32 %110)
%112 = icmp eq i32 %111, %110
br i1 %112, label %116, label %113
113: ; preds = %109
%114 = load i32, i32* @stderr
%115 = call i32 @fprintf(i32 %114, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br label %116
116: ; preds = %113, %109
%117 = load i32, i32* @BUFSIZ
%118 = call i32 @read(i32 %36, i8* %10, i32 %117)
%119 = icmp sgt i32 %118, 0
br i1 %119, label %109, label %120
120: ; preds = %64, %116, %56, %101
%121 = phi i32 [ %99, %101 ], [ %46, %56 ], [ %99, %116 ], [ %46, %64 ]
%122 = call i32 @close(i32 %121)
br label %123
123: ; preds = %120, %27
%124 = phi i32 [ %36, %120 ], [ %21, %27 ]
%125 = call i32 @close(i32 %124)
ret void
}