#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int main() {
  FILE *versionfile = fopen("../VERSION", "r");
  if (versionfile == NULL) {
    fprintf(stderr, "Can't open ../VERSION\n");
    return 1;
  }
  FILE *infoplistfile = fopen("Info.plist", "r");
  if (infoplistfile == NULL) {
    fprintf(stderr, "Can't open Info.plist\n");
    return 1;
  }
  char version[100];
  if (fscanf(versionfile, "%99s", version) != 1) {
    fprintf(stderr, "Can't read version number\n");
    return 1;
  }
  int vlen = strlen(version);
  if (vlen == 0) {
    fprintf(stderr, "Version is empty\n");
    return 1;
  }
  char c = version[vlen - 1];
  if (!isdigit(c)) {
    version[vlen - 1] = '.';
    char *p = version + vlen;
    sprintf(p, "%d", ((int)c) - 96);
  }
  char short_version[100];
  char *dot = strchr(version, '.');
  strncpy(short_version, version, dot - version);
  strcat(short_version, dot + 1);
  int state = 0;
  char line[1024], newline[1024];
  FILE *newinfoplistfile = fopen("Info.plist.new", "w");
  int success = 0;
  char *p, *p2;
  int len;
  while (fgets(line, 1024, infoplistfile) != NULL) {
    switch (state) {
    case 0:
      if (strstr(line, "<key>CFBundleVersion</key>") != NULL)
        state = 1;
      else if (strstr(line, "<key>CFBundleShortVersionString</key>") != NULL)
        state = 2;
      break;
    case 1:
    case 2:
      p = strstr(line, "<string>");
      if (p == NULL)
        goto done;
      p += 8;
      p2 = strstr(line, "</string>");
      if (p2 == NULL)
        goto done;
      len = p - line;
      memcpy(newline, line, len);
      newline[len] = 0;
      strcat(newline, state == 1 ? version : short_version);
      strcat(newline, p2);
      strcpy(line, newline);
      success |= state;
      state = 0;
      break;
    }
    fputs(line, newinfoplistfile);
  }
done:
  fclose(infoplistfile);
  fclose(newinfoplistfile);
  if (success == 3) {
    rename("Info.plist.new", "Info.plist");
    return 0;
  } else {
    remove("Info.plist.new");
    fprintf(stderr, "Updating CFBundleVersion or CFBundleShortVersionString in "
                    "Info.plist failed.\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x950,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xdd7(%rip),%rdi
lea    0xddb(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1265 <main+0x55>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
call   10d0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1674 <main+0x464>
lea    0xdb8(%rip),%rdi
lea    0xd98(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12a8 <main+0x98>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
call   10d0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1674 <main+0x464>
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xd8f(%rip),%rsi
call   10b0 <fscanf@plt>
cmp    $0x1,%eax
je     12e6 <main+0xd6>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
call   10d0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1674 <main+0x464>
lea    -0x80(%rbp),%rdi
call   1080 <strlen@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jne    1323 <main+0x113>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
call   10d0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1674 <main+0x464>
mov    -0x84(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x80(%rbp,%rax,1),%al
mov    %al,-0x85(%rbp)
movsbl -0x85(%rbp),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%eax
jne    138f <main+0x17f>
mov    -0x84(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x2e,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rax
movslq -0x84(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rdi
movsbl -0x85(%rbp),%edx
sub    $0x60,%edx
lea    0xcee(%rip),%rsi
call   1120 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x2e,%esi
call   1090 <strchr@plt>
mov    %rax,-0x108(%rbp)
lea    -0x100(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x108(%rbp),%rax
lea    -0x80(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    -0x100(%rbp),%rdi
mov    -0x108(%rbp),%rsi
add    $0x1,%rsi
call   1110 <strcat@plt>
movl   $0x0,-0x10c(%rbp)
lea    0xc8f(%rip),%rdi
lea    0xc95(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x918(%rbp)
movl   $0x0,-0x91c(%rbp)
lea    -0x510(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   10c0 <fgets@plt>
cmp    $0x0,%rax
je     1606 <main+0x3f6>
mov    -0x10c(%rbp),%eax
mov    %eax,-0x938(%rbp)
test   %eax,%eax
je     1458 <main+0x248>
jmp    1441 <main+0x231>
mov    -0x938(%rbp),%eax
add    $0xffffffff,%eax
sub    $0x2,%eax
jb     14b5 <main+0x2a5>
jmp    15ee <main+0x3de>
lea    -0x510(%rbp),%rdi
lea    0xc24(%rip),%rsi
call   1130 <strstr@plt>
cmp    $0x0,%rax
je     1484 <main+0x274>
movl   $0x1,-0x10c(%rbp)
jmp    14b0 <main+0x2a0>
lea    -0x510(%rbp),%rdi
lea    0xc13(%rip),%rsi
call   1130 <strstr@plt>
cmp    $0x0,%rax
je     14ab <main+0x29b>
movl   $0x2,-0x10c(%rbp)
jmp    14b0 <main+0x2a0>
jmp    15ee <main+0x3de>
lea    -0x510(%rbp),%rdi
lea    0xc08(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x928(%rbp)
cmpq   $0x0,-0x928(%rbp)
jne    14e2 <main+0x2d2>
jmp    160b <main+0x3fb>
mov    -0x928(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x928(%rbp)
lea    -0x510(%rbp),%rdi
lea    0xbd2(%rip),%rsi
call   1130 <strstr@plt>
mov    %rax,-0x930(%rbp)
cmpq   $0x0,-0x930(%rbp)
jne    1521 <main+0x311>
jmp    160b <main+0x3fb>
mov    -0x928(%rbp),%rax
lea    -0x510(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x934(%rbp)
lea    -0x910(%rbp),%rdi
lea    -0x510(%rbp),%rsi
mov    -0x934(%rbp),%edx
call   10e0 <memcpy@plt>
movslq -0x934(%rbp),%rax
movb   $0x0,-0x910(%rbp,%rax,1)
lea    -0x910(%rbp),%rax
mov    %rax,-0x940(%rbp)
cmpl   $0x1,-0x10c(%rbp)
jne    158b <main+0x37b>
lea    -0x80(%rbp),%rax
mov    %rax,-0x948(%rbp)
jmp    1599 <main+0x389>
lea    -0x100(%rbp),%rax
mov    %rax,-0x948(%rbp)
mov    -0x940(%rbp),%rdi
mov    -0x948(%rbp),%rsi
call   1110 <strcat@plt>
lea    -0x910(%rbp),%rdi
mov    -0x930(%rbp),%rsi
call   1110 <strcat@plt>
lea    -0x510(%rbp),%rdi
lea    -0x910(%rbp),%rsi
call   1060 <strcpy@plt>
mov    -0x10c(%rbp),%eax
or     -0x91c(%rbp),%eax
mov    %eax,-0x91c(%rbp)
movl   $0x0,-0x10c(%rbp)
lea    -0x510(%rbp),%rdi
mov    -0x918(%rbp),%rsi
call   10a0 <fputs@plt>
jmp    1409 <main+0x1f9>
jmp    160b <main+0x3fb>
mov    -0x18(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x918(%rbp),%rdi
call   1070 <fclose@plt>
cmpl   $0x3,-0x91c(%rbp)
jne    164c <main+0x43c>
lea    0xa47(%rip),%rdi
lea    0x9e9(%rip),%rsi
call   1100 <rename@plt>
movl   $0x0,-0x4(%rbp)
jmp    1674 <main+0x464>
lea    0xa28(%rip),%rdi
call   1040 <remove@plt>
mov    0x2981(%rip),%rax
mov    (%rax),%edi
lea    0xa76(%rip),%rsi
call   10d0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x950,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8f8,%rsp
lea    0xdd8(%rip),%rdi
lea    0xddc(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     1478 <main+0x268>
mov    %rax,%rbx
lea    0xddd(%rip),%rdi
lea    0xdbd(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     148d <main+0x27d>
mov    %rax,%r13
lea    0xde0(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   10b0 <fscanf@plt>
cmp    $0x1,%eax
jne    149f <main+0x28f>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <strlen@plt>
test   %eax,%eax
je     14b1 <main+0x2a1>
movslq %eax,%rbp
movsbl -0x1(%rbp,%rbx,1),%ebx
mov    %ebx,%edi
call   1050 <isdigit@plt>
test   %eax,%eax
jne    12c2 <main+0xb2>
movb   $0x2e,0xf(%rsp,%rbp,1)
lea    (%rsp,%rbp,1),%rdi
add    $0x10,%rdi
add    $0xffffffa0,%ebx
lea    0xdbd(%rip),%rsi
mov    %ebx,%edx
call   1120 <sprintf@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x2e,%esi
call   1090 <strchr@plt>
mov    %rax,%rbx
mov    %ebx,%edx
sub    %ebp,%edx
lea    0x80(%rsp),%r14
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <strncpy@plt>
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1110 <strcat@plt>
lea    0xd77(%rip),%rdi
lea    0xd7d(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,0x8(%rsp)
lea    0x4f0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   10c0 <fgets@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     14ca <main+0x2ba>
xor    %r12d,%r12d
mov    %r13,(%rsp)
jmp    1376 <main+0x166>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
call   10a0 <fputs@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   10c0 <fgets@plt>
test   %rax,%rax
je     14ca <main+0x2ba>
lea    -0x1(%r12),%eax
cmp    $0x2,%eax
jae    1430 <main+0x220>
mov    %rbx,%rdi
lea    0xd3d(%rip),%rsi
call   1130 <strstr@plt>
test   %rax,%rax
je     14ca <main+0x2ba>
mov    %rax,%r14
mov    %r15d,%r13d
mov    %rbx,%rdi
lea    0xd28(%rip),%rsi
call   1130 <strstr@plt>
test   %rax,%rax
je     14c3 <main+0x2b3>
mov    %rax,%r15
sub    %rbx,%r14
add    $0x8,%r14
lea    0xf0(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   10e0 <memcpy@plt>
movslq %r14d,%rax
movb   $0x0,0xf0(%rsp,%rax,1)
cmp    $0x1,%r12d
lea    0x80(%rsp),%rsi
lea    0x10(%rsp),%rax
cmove  %rax,%rsi
mov    %rbp,%rdi
call   1110 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1110 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <strcpy@plt>
mov    %r13d,%r15d
or     %r12d,%r15d
xor    %r12d,%r12d
mov    (%rsp),%r13
jmp    1350 <main+0x140>
nopw   0x0(%rax,%rax,1)
test   %r12d,%r12d
jne    1350 <main+0x140>
mov    %rbx,%rdi
lea    0xc47(%rip),%rsi
call   1130 <strstr@plt>
mov    $0x1,%r12d
test   %rax,%rax
jne    1350 <main+0x140>
mov    %rbx,%rdi
lea    0xc44(%rip),%rsi
call   1130 <strstr@plt>
xor    %r12d,%r12d
test   %rax,%rax
setne  %r12b
add    %r12d,%r12d
jmp    1350 <main+0x140>
mov    0x2b61(%rip),%rax
mov    (%rax),%edi
lea    0xb85(%rip),%rsi
jmp    150e <main+0x2fe>
mov    0x2b4c(%rip),%rax
mov    (%rax),%edi
lea    0xb92(%rip),%rsi
jmp    150e <main+0x2fe>
mov    0x2b3a(%rip),%rax
mov    (%rax),%edi
lea    0xb9c(%rip),%rsi
jmp    150e <main+0x2fe>
mov    0x2b28(%rip),%rax
mov    (%rax),%edi
lea    0xba5(%rip),%rsi
jmp    150e <main+0x2fe>
mov    %r13d,%r15d
mov    (%rsp),%r13
mov    %r13,%rdi
call   1070 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1070 <fclose@plt>
lea    0xb98(%rip),%rdi
cmp    $0x3,%r15d
jne    14f9 <main+0x2e9>
lea    0xb34(%rip),%rsi
call   1100 <rename@plt>
xor    %eax,%eax
jmp    1518 <main+0x308>
call   1040 <remove@plt>
mov    0x2adb(%rip),%rax
mov    (%rax),%edi
lea    0xbd0(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%eax
add    $0x8f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"../VERSION\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"Can't open ../VERSION\0A\00"
@.str.3 = [11 x i8] c"Info.plist\00"
@.str.4 = [23 x i8] c"Can't open Info.plist\0A\00"
@.str.5 = [5 x i8] c"%99s\00"
@.str.6 = [27 x i8] c"Can't read version number\0A\00"
@.str.7 = [18 x i8] c"Version is empty\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [15 x i8] c"Info.plist.new\00"
@.str.10 = [2 x i8] c"w\00"
@.str.11 = [27 x i8] c"<key>CFBundleVersion</key>\00"
@.str.12 = [38 x i8] c"<key>CFBundleShortVersionString</key>\00"
@.str.13 = [9 x i8] c"<string>\00"
@.str.14 = [10 x i8] c"</string>\00"
@.str.15 = [78 x i8] c"Updating CFBundleVersion or CFBundleShortVersionString in Info.plist failed.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [100 x i8]
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8*
%8 = alloca [100 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca [1024 x i8]
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32
store i32 0, i32* %1
%18 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %2
%19 = load i32*, i32** %2
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %0
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %171
24: ; preds = %0
%25 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %3
%26 = load i32*, i32** %3
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %171
31: ; preds = %24
%32 = load i32*, i32** %2
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%34 = call i32 @fscanf(i32* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%35 = icmp ne i32 %34, 1
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %171
39: ; preds = %31
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
store i32 %41, i32* %5
%42 = load i32, i32* %5
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %1
br label %171
47: ; preds = %39
%48 = load i32, i32* %5
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %50
%52 = load i8, i8* %51
store i8 %52, i8* %6
%53 = load i8, i8* %6
%54 = call i32 @isdigit(i8 signext %53)
%55 = icmp ne i32 %54, 0
br i1 %55, label %70, label %56
56: ; preds = %47
%57 = load i32, i32* %5
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %59
store i8 46, i8* %60
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%62 = load i32, i32* %5
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8* %64, i8** %7
%65 = load i8*, i8** %7
%66 = load i8, i8* %6
%67 = sext i8 %66 to i32
%68 = sub nsw i32 %67, 96
%69 = call i32 @sprintf(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %56, %47
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%72 = call i8* @strchr(i8* %71, i8 signext 46)
store i8* %72, i8** %9
%73 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%75 = load i8*, i8** %9
%76 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%77 = ptrtoint i8* %75 to i64
%78 = ptrtoint i8* %76 to i64
%79 = sub i64 %77, %78
%80 = trunc i64 %79 to i32
%81 = call i32 @strncpy(i8* %73, i8* %74, i32 %80)
%82 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%83 = load i8*, i8** %9
%84 = getelementptr inbounds i8, i8* %83, i64 1
%85 = call i32 @strcat(i8* %82, i8* %84)
store i32 0, i32* %10
%86 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i32* %86, i32** %13
store i32 0, i32* %14
br label %87
87: ; preds = %153, %70
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%89 = load i32*, i32** %3
%90 = call i32* @fgets(i8* %88, i32 1024, i32* %89)
%91 = icmp ne i32* %90, null
br i1 %91, label %92, label %157
92: ; preds = %87
%93 = load i32, i32* %10
switch i32 %93, label %153 [
i32 0, label %94
i32 1, label %106
i32 2, label %106
]
94: ; preds = %92
%95 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%96 = call i8* @strstr(i8* %95, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%97 = icmp ne i8* %96, null
br i1 %97, label %98, label %99
98: ; preds = %94
store i32 1, i32* %10
br label %105
99: ; preds = %94
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%101 = call i8* @strstr(i8* %100, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0))
%102 = icmp ne i8* %101, null
br i1 %102, label %103, label %104
103: ; preds = %99
store i32 2, i32* %10
br label %104
104: ; preds = %103, %99
br label %105
105: ; preds = %104, %98
br label %153
106: ; preds = %92, %92
%107 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%108 = call i8* @strstr(i8* %107, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0))
store i8* %108, i8** %15
%109 = load i8*, i8** %15
%110 = icmp eq i8* %109, null
br i1 %110, label %111, label %112
111: ; preds = %106
br label %158
112: ; preds = %106
%113 = load i8*, i8** %15
%114 = getelementptr inbounds i8, i8* %113, i64 8
store i8* %114, i8** %15
%115 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%116 = call i8* @strstr(i8* %115, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0))
store i8* %116, i8** %16
%117 = load i8*, i8** %16
%118 = icmp eq i8* %117, null
br i1 %118, label %119, label %120
119: ; preds = %112
br label %158
120: ; preds = %112
%121 = load i8*, i8** %15
%122 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%123 = ptrtoint i8* %121 to i64
%124 = ptrtoint i8* %122 to i64
%125 = sub i64 %123, %124
%126 = trunc i64 %125 to i32
store i32 %126, i32* %17
%127 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%128 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%129 = load i32, i32* %17
%130 = call i32 @memcpy(i8* %127, i8* %128, i32 %129)
%131 = load i32, i32* %17
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 %132
store i8 0, i8* %133
%134 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%135 = load i32, i32* %10
%136 = icmp eq i32 %135, 1
br i1 %136, label %137, label %139
137: ; preds = %120
%138 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
br label %141
139: ; preds = %120
%140 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
br label %141
141: ; preds = %139, %137
%142 = phi i8* [ %138, %137 ], [ %140, %139 ]
%143 = call i32 @strcat(i8* %134, i8* %142)
%144 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%145 = load i8*, i8** %16
%146 = call i32 @strcat(i8* %144, i8* %145)
%147 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%148 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%149 = call i32 @strcpy(i8* %147, i8* %148)
%150 = load i32, i32* %10
%151 = load i32, i32* %14
%152 = or i32 %151, %150
store i32 %152, i32* %14
store i32 0, i32* %10
br label %153
153: ; preds = %92, %141, %105
%154 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%155 = load i32*, i32** %13
%156 = call i32 @fputs(i8* %154, i32* %155)
br label %87
157: ; preds = %87
br label %158
158: ; preds = %157, %119, %111
%159 = load i32*, i32** %3
%160 = call i32 @fclose(i32* %159)
%161 = load i32*, i32** %13
%162 = call i32 @fclose(i32* %161)
%163 = load i32, i32* %14
%164 = icmp eq i32 %163, 3
br i1 %164, label %165, label %167
165: ; preds = %158
%166 = call i32 @rename(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %171
167: ; preds = %158
%168 = call i32 @remove(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%169 = load i32, i32* @stderr
%170 = call i32 @fprintf(i32 %169, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.15, i64 0, i64 0))
store i32 1, i32* %1
br label %171
171: ; preds = %167, %165, %44, %36, %28, %21
%172 = load i32, i32* %1
ret i32 %172
}

LLVM IR (-O2):
@.str = [11 x i8] c"../VERSION\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"Can't open ../VERSION\0A\00"
@.str.3 = [11 x i8] c"Info.plist\00"
@.str.4 = [23 x i8] c"Can't open Info.plist\0A\00"
@.str.5 = [5 x i8] c"%99s\00"
@.str.6 = [27 x i8] c"Can't read version number\0A\00"
@.str.7 = [18 x i8] c"Version is empty\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [15 x i8] c"Info.plist.new\00"
@.str.10 = [2 x i8] c"w\00"
@.str.11 = [27 x i8] c"<key>CFBundleVersion</key>\00"
@.str.12 = [38 x i8] c"<key>CFBundleShortVersionString</key>\00"
@.str.13 = [9 x i8] c"<string>\00"
@.str.14 = [10 x i8] c"</string>\00"
@.str.15 = [78 x i8] c"Updating CFBundleVersion or CFBundleShortVersionString in Info.plist failed.\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %111
10: ; preds = %0
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %111
16: ; preds = %10
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%18 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %17)
%19 = icmp eq i32 %18, 1
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %109
23: ; preds = %16
%24 = call i32 @strlen(i8* %17)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
br label %109
29: ; preds = %23
%30 = add nsw i32 %24, -1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = call i32 @isdigit(i8 signext %33)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %29
store i8 46, i8* %32
%37 = sext i32 %24 to i64
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %37
%39 = sext i8 %33 to i32
%40 = add nsw i32 %39, -96
%41 = call i32 @sprintf(i8* %38, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %36, %29
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%44 = call i8* @strchr(i8* %17, i8 signext 46)
%45 = ptrtoint i8* %44 to i64
%46 = ptrtoint [100 x i8]* %1 to i64
%47 = sub i64 %45, %46
%48 = trunc i64 %47 to i32
%49 = call i32 @strncpy(i8* %43, i8* %17, i32 %48)
%50 = getelementptr inbounds i8, i8* %44, i64 1
%51 = call i32 @strcat(i8* %43, i8* %50)
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%54 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%55 = call i32* @fgets(i8* %52, i32 1024, i32* %11)
%56 = icmp eq i32* %55, null
br i1 %56, label %96, label %57
57: ; preds = %42
%58 = ptrtoint [1024 x i8]* %3 to i64
br label %59
59: ; preds = %57, %90
%60 = phi i32 [ 0, %57 ], [ %92, %90 ]
%61 = phi i32 [ 0, %57 ], [ %91, %90 ]
switch i32 %61, label %90 [
i32 0, label %62
i32 1, label %69
i32 2, label %69
]
62: ; preds = %59
%63 = call i8* @strstr(i8* %52, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%64 = icmp eq i8* %63, null
br i1 %64, label %65, label %90
65: ; preds = %62
%66 = call i8* @strstr(i8* %52, i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0))
%67 = icmp eq i8* %66, null
%68 = select i1 %67, i32 0, i32 2
br label %90
69: ; preds = %59, %59
%70 = call i8* @strstr(i8* %52, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0))
%71 = icmp eq i8* %70, null
br i1 %71, label %96, label %72
72: ; preds = %69
%73 = call i8* @strstr(i8* %52, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0))
%74 = icmp eq i8* %73, null
br i1 %74, label %96, label %75
75: ; preds = %72
%76 = getelementptr inbounds i8, i8* %70, i64 8
%77 = ptrtoint i8* %76 to i64
%78 = sub i64 %77, %58
%79 = trunc i64 %78 to i32
%80 = call i32 @memcpy(i8* %53, i8* %52, i32 %79)
%81 = shl i64 %78, 32
%82 = ashr exact i64 %81, 32
%83 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %82
store i8 0, i8* %83
%84 = icmp eq i32 %61, 1
%85 = select i1 %84, i8* %17, i8* %43
%86 = call i32 @strcat(i8* %53, i8* %85)
%87 = call i32 @strcat(i8* %53, i8* %73)
%88 = call i32 @strcpy(i8* %52, i8* %53)
%89 = or i32 %60, %61
br label %90
90: ; preds = %65, %62, %59, %75
%91 = phi i32 [ %61, %59 ], [ 0, %75 ], [ 1, %62 ], [ %68, %65 ]
%92 = phi i32 [ %60, %59 ], [ %89, %75 ], [ %60, %62 ], [ %60, %65 ]
%93 = call i32 @fputs(i8* %52, i32* %54)
%94 = call i32* @fgets(i8* %52, i32 1024, i32* %11)
%95 = icmp eq i32* %94, null
br i1 %95, label %96, label %59
96: ; preds = %69, %72, %90, %42
%97 = phi i32 [ 0, %42 ], [ %92, %90 ], [ %60, %72 ], [ %60, %69 ]
%98 = call i32 @fclose(i32* %11)
%99 = call i32 @fclose(i32* %54)
%100 = icmp eq i32 %97, 3
br i1 %100, label %101, label %103
101: ; preds = %96
%102 = call i32 @rename(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %107
103: ; preds = %96
%104 = call i32 @remove(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%105 = load i32, i32* @stderr
%106 = call i32 @fprintf(i32 %105, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.15, i64 0, i64 0))
br label %107
107: ; preds = %103, %101
%108 = phi i32 [ 0, %101 ], [ 1, %103 ]
br label %109
109: ; preds = %26, %107, %20
%110 = phi i32 [ 1, %20 ], [ 1, %26 ], [ %108, %107 ]
br label %111
111: ; preds = %13, %109, %7
%112 = phi i32 [ 1, %7 ], [ 1, %13 ], [ %110, %109 ]
ret i32 %112
}