#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*/ tmpname;
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ remove(char *);
int remove_tag(char *, char const *);
scalar_t__ rename(char *, char const *);
int /*<<< orphan*/ should_tag(char *, char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write_tagged(int /*<<< orphan*/ *, char *, char const *,
                                int);
int main(int argc, char **argv) {
  const char *filename = "/system/build.prop";
  const char *propname = "ro.build.fingerprint";
  const char *tag = NULL;
  int do_remove = 0, do_number = 0;
  int opt;
  while ((opt = getopt(argc, argv, "f:p:rn")) != -1) {
    switch (opt) {
    case 'f':
      filename = optarg;
      break;
    case 'p':
      propname = optarg;
      break;
    case 'r':
      do_remove = 1;
      break;
    case 'n':
      do_number = 1;
      break;
    case '?':
      return 2;
    }
  }
  if (argc != optind + 1) {
    fprintf(stderr,
            "usage: add-property-tag [flags] tag-to-add\n"
            "flags: -f /dir/file.prop (default /system/build.prop)\n"
            "       -p prop.name (default ro.build.fingerprint)\n"
            "       -r (if set, remove the tag rather than adding it)\n"
            "       -n (if set, add and increment a number after the tag)\n");
    return 2;
  }
  tag = argv[optind];
  FILE *input = fopen(filename, "r");
  if (input == NULL) {
    fprintf(stderr, "can't read %s: %s\n", filename, strerror(errno));
    return 1;
  }
  char tmpname[PATH_MAX];
  snprintf(tmpname, sizeof(tmpname), "%s.tmp", filename);
  FILE *output = fopen(tmpname, "w");
  if (output == NULL) {
    fprintf(stderr, "can't write %s: %s\n", tmpname, strerror(errno));
    return 1;
  }
  int found = 0;
  char line[4096];
  while (fgets(line, sizeof(line), input)) {
    if (!should_tag(line, propname)) {
      fputs(line, output);
    } else {
      found = 1;
      int number = remove_tag(line, tag);
      if (do_remove) {
        fputs(line, output);
      } else {
        write_tagged(output, line, tag, number + do_number);
      }
    }
  }
  fclose(input);
  fclose(output);
  if (!found) {
    fprintf(stderr, "property %s not found in %s\n", propname, filename);
    remove(tmpname);
    return 1;
  }
  if (rename(tmpname, filename)) {
    fprintf(stderr, "can't rename %s to %s: %s\n", tmpname, filename,
            strerror(errno));
    remove(tmpname);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe10(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe18(%rip),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe05(%rip),%rdx
call   10e0 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     12ea <main+0x11a>
mov    -0x34(%rbp),%eax
mov    %eax,-0x1068(%rbp)
sub    $0x3f,%eax
je     12d9 <main+0x109>
jmp    124b <main+0x7b>
mov    -0x1068(%rbp),%eax
sub    $0x66,%eax
je     129b <main+0xcb>
jmp    125f <main+0x8f>
mov    -0x1068(%rbp),%eax
sub    $0x6e,%eax
je     12cd <main+0xfd>
jmp    1273 <main+0xa3>
mov    -0x1068(%rbp),%eax
sub    $0x70,%eax
je     12ae <main+0xde>
jmp    1287 <main+0xb7>
mov    -0x1068(%rbp),%eax
sub    $0x72,%eax
je     12c1 <main+0xf1>
jmp    12e5 <main+0x115>
mov    0x2d56(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    12e5 <main+0x115>
mov    0x2d43(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12e5 <main+0x115>
movl   $0x1,-0x2c(%rbp)
jmp    12e5 <main+0x115>
movl   $0x1,-0x30(%rbp)
jmp    12e5 <main+0x115>
movl   $0x2,-0x4(%rbp)
jmp    1608 <main+0x438>
jmp    1215 <main+0x45>
mov    -0x8(%rbp),%eax
mov    0x2ce4(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     1324 <main+0x154>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
lea    0xd1e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1608 <main+0x438>
mov    -0x10(%rbp),%rax
mov    0x2ca9(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    13ab <main+0x1db>
mov    0x2c68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1074(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1070(%rbp)
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x1074(%rbp),%edi
mov    -0x1070(%rbp),%rdx
mov    %rax,%rcx
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1608 <main+0x438>
mov    0x2c36(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x1080(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x50(%rbp)
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
lea    0xd68(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x1080(%rbp),%rdi
lea    0xd5c(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    145c <main+0x28c>
mov    0x2bb3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1084(%rbp)
mov    0x2b9c(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x1084(%rbp),%edi
mov    -0x1080(%rbp),%rdx
mov    %rax,%rcx
lea    0xd16(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    1601 <main+0x431>
movl   $0x0,-0x60(%rbp)
lea    -0x1060(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    $0x1000,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     1513 <main+0x343>
lea    -0x1060(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <should_tag@plt>
cmp    $0x0,%eax
jne    14b0 <main+0x2e0>
lea    -0x1060(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1080 <fputs@plt>
jmp    150e <main+0x33e>
movl   $0x1,-0x60(%rbp)
lea    -0x1060(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10b0 <remove_tag@plt>
mov    %eax,-0x1064(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     14ec <main+0x31c>
lea    -0x1060(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1080 <fputs@plt>
jmp    1509 <main+0x339>
mov    -0x58(%rbp),%rdi
lea    -0x1060(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x1064(%rbp),%ecx
add    -0x30(%rbp),%ecx
call   1040 <write_tagged@plt>
jmp    150e <main+0x33e>
jmp    1463 <main+0x293>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x60(%rbp)
jne    156d <main+0x39d>
mov    0x2a92(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xc25(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x1080(%rbp),%rdi
call   1030 <remove@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    1601 <main+0x431>
mov    -0x1080(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10d0 <rename@plt>
cmp    $0x0,%rax
je     15f3 <main+0x423>
mov    0x2a3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1094(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1090(%rbp)
mov    0x2a18(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x1094(%rbp),%edi
mov    -0x1090(%rbp),%rcx
mov    -0x1080(%rbp),%rdx
mov    %rax,%r8
lea    0xbbc(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x1080(%rbp),%rdi
call   1030 <remove@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
jmp    1601 <main+0x431>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x5c(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
lea    0xe44(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe4c(%rip),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe4f(%rip),%r13
lea    0xdec(%rip),%r14
mov    0x2ddd(%rip),%r12
movl   $0x0,-0x30(%rbp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r13,%rdx
call   10e0 <getopt@plt>
lea    -0x66(%rax),%ecx
cmp    $0xc,%ecx
ja     1260 <main+0x90>
movslq (%r14,%rcx,4),%rax
add    %r14,%rax
jmp    *%rax
mov    (%r12),%rax
mov    %rax,-0x40(%rbp)
jmp    1230 <main+0x60>
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     128b <main+0xbb>
cmp    $0x3f,%eax
jne    1230 <main+0x60>
jmp    13aa <main+0x1da>
movl   $0x1,-0x2c(%rbp)
jmp    1230 <main+0x60>
mov    (%r12),%rax
mov    %rax,-0x48(%rbp)
jmp    1230 <main+0x60>
movl   $0x1,-0x30(%rbp)
jmp    1230 <main+0x60>
mov    0x2d46(%rip),%rax
movslq (%rax),%rax
lea    0x1(%rax),%ecx
cmp    %ebx,%ecx
jne    13b4 <main+0x1e4>
mov    (%r15,%rax,8),%r13
lea    0xec3(%rip),%rsi
mov    -0x40(%rbp),%rbx
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1444 <main+0x274>
mov    %rax,%r12
mov    %rsp,-0x38(%rbp)
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r14
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe98(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rcx
call   1060 <snprintf@plt>
lea    0xe8d(%rip),%rsi
mov    %r14,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     147a <main+0x2aa>
mov    %rax,%r15
mov    %r14,-0x50(%rbp)
lea    -0x1050(%rbp),%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1090 <fgets@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     13d5 <main+0x205>
lea    -0x1050(%rbp),%r14
jmp    135d <main+0x18d>
nopl   (%rax)
mov    %r15,%rsi
call   1080 <fputs@plt>
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %r12,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     13d5 <main+0x205>
mov    %r14,%rdi
mov    -0x48(%rbp),%rsi
call   1070 <should_tag@plt>
mov    %r14,%rdi
test   %eax,%eax
je     1340 <main+0x170>
mov    %r13,%rsi
call   10b0 <remove_tag@plt>
cmpl   $0x0,-0x30(%rbp)
je     1390 <main+0x1c0>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <fputs@plt>
jmp    13a3 <main+0x1d3>
nopl   0x0(%rax,%rax,1)
add    -0x2c(%rbp),%eax
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
mov    %eax,%ecx
call   1040 <write_tagged@plt>
mov    $0x1,%ebx
jmp    1348 <main+0x178>
mov    $0x2,%eax
jmp    14f1 <main+0x321>
mov    0x2c0d(%rip),%rax
mov    (%rax),%edi
lea    0xc9f(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x2,%eax
jmp    14f1 <main+0x321>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
test   %ebx,%ebx
je     14b2 <main+0x2e2>
mov    -0x50(%rbp),%r15
mov    %r15,%rdi
mov    -0x40(%rbp),%rbx
mov    %rbx,%rsi
call   10d0 <rename@plt>
test   %rax,%rax
je     14e8 <main+0x318>
mov    0x2bb8(%rip),%rax
mov    (%rax),%r14d
mov    0x2ba6(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd95(%rip),%rsi
mov    %r14d,%edi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    -0x38(%rbp),%rbx
jmp    14d9 <main+0x309>
mov    0x2b7d(%rip),%rax
mov    (%rax),%r14d
mov    0x2b6b(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd0d(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%eax
jmp    14f1 <main+0x321>
mov    0x2b47(%rip),%rax
mov    (%rax),%ebx
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xcf4(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%eax
mov    -0x38(%rbp),%rsp
jmp    14f1 <main+0x321>
mov    0x2b0f(%rip),%rax
mov    (%rax),%edi
lea    0xcde(%rip),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    -0x38(%rbp),%rbx
mov    -0x50(%rbp),%r15
mov    %r15,%rdi
call   1030 <remove@plt>
mov    $0x1,%eax
jmp    14ee <main+0x31e>
xor    %eax,%eax
mov    -0x38(%rbp),%rbx
mov    %rbx,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/system/build.prop\00"
@.str.1 = [21 x i8] c"ro.build.fingerprint\00"
@.str.2 = [7 x i8] c"f:p:rn\00"
@optarg = global i8* null
@optind = global i32 0
@stderr = global i32 0
@.str.3 = [267 x i8] c"usage: add-property-tag [flags] tag-to-add\0Aflags: -f /dir/file.prop (default /system/build.prop)\0A -p prop.name (default ro.build.fingerprint)\0A -r (if set, remove the tag rather than adding it)\0A -n (if set, add and increment a number after the tag)\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [19 x i8] c"can't read %s: %s\0A\00"
@errno = global i32 0
@PATH_MAX = global i32 0
@.str.6 = [7 x i8] c"%s.tmp\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [20 x i8] c"can't write %s: %s\0A\00"
@.str.9 = [29 x i8] c"property %s not found in %s\0A\00"
@.str.10 = [27 x i8] c"can't rename %s to %s: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca [4096 x i8]
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i8* null, i8** %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %20
20: ; preds = %34, %2
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @getopt(i32 %21, i8** %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 %23, i32* %11
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %35
25: ; preds = %20
%26 = load i32, i32* %11
switch i32 %26, label %34 [
i32 102, label %27
i32 112, label %29
i32 114, label %31
i32 110, label %32
i32 63, label %33
]
27: ; preds = %25
%28 = load i8*, i8** @optarg
store i8* %28, i8** %6
br label %34
29: ; preds = %25
%30 = load i8*, i8** @optarg
store i8* %30, i8** %7
br label %34
31: ; preds = %25
store i32 1, i32* %9
br label %34
32: ; preds = %25
store i32 1, i32* %10
br label %34
33: ; preds = %25
store i32 2, i32* %3
br label %137
34: ; preds = %25, %32, %31, %29, %27
br label %20
35: ; preds = %20
%36 = load i32, i32* %4
%37 = load i32, i32* @optind
%38 = add nsw i32 %37, 1
%39 = icmp ne i32 %36, %38
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([267 x i8], [267 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %137
43: ; preds = %35
%44 = load i8**, i8*** %5
%45 = load i32, i32* @optind
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
store i8* %48, i8** %8
%49 = load i8*, i8** %6
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %50, i32** %12
%51 = load i32*, i32** %12
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %59
53: ; preds = %43
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %6
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %55, i8* %57)
store i32 1, i32* %3
br label %137
59: ; preds = %43
%60 = load i32, i32* @PATH_MAX
%61 = zext i32 %60 to i64
%62 = call i8* @llvm.stacksave()
store i8* %62, i8** %13
%63 = alloca i8, i64 %61
store i64 %61, i64* %14
%64 = trunc i64 %61 to i32
%65 = load i8*, i8** %6
%66 = call i32 @snprintf(i8* %63, i32 %64, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %65)
%67 = call i32* @fopen(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %67, i32** %15
%68 = load i32*, i32** %15
%69 = icmp eq i32* %68, null
br i1 %69, label %70, label %75
70: ; preds = %59
%71 = load i32, i32* @stderr
%72 = load i32, i32* @errno
%73 = call i8* @strerror(i32 %72)
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %63, i8* %73)
store i32 1, i32* %3
store i32 1, i32* %16
br label %135
75: ; preds = %59
store i32 0, i32* %17
br label %76
76: ; preds = %109, %75
%77 = getelementptr inbounds [4096 x i8], [4096 x i8]* %18, i64 0, i64 0
%78 = load i32*, i32** %12
%79 = call i64 @fgets(i8* %77, i32 4096, i32* %78)
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %110
81: ; preds = %76
%82 = getelementptr inbounds [4096 x i8], [4096 x i8]* %18, i64 0, i64 0
%83 = load i8*, i8** %7
%84 = call i32 @should_tag(i8* %82, i8* %83)
%85 = icmp ne i32 %84, 0
br i1 %85, label %90, label %86
86: ; preds = %81
%87 = getelementptr inbounds [4096 x i8], [4096 x i8]* %18, i64 0, i64 0
%88 = load i32*, i32** %15
%89 = call i32 @fputs(i8* %87, i32* %88)
br label %109
90: ; preds = %81
store i32 1, i32* %17
%91 = getelementptr inbounds [4096 x i8], [4096 x i8]* %18, i64 0, i64 0
%92 = load i8*, i8** %8
%93 = call i32 @remove_tag(i8* %91, i8* %92)
store i32 %93, i32* %19
%94 = load i32, i32* %9
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %90
%97 = getelementptr inbounds [4096 x i8], [4096 x i8]* %18, i64 0, i64 0
%98 = load i32*, i32** %15
%99 = call i32 @fputs(i8* %97, i32* %98)
br label %108
100: ; preds = %90
%101 = load i32*, i32** %15
%102 = getelementptr inbounds [4096 x i8], [4096 x i8]* %18, i64 0, i64 0
%103 = load i8*, i8** %8
%104 = load i32, i32* %19
%105 = load i32, i32* %10
%106 = add nsw i32 %104, %105
%107 = call i32 @write_tagged(i32* %101, i8* %102, i8* %103, i32 %106)
br label %108
108: ; preds = %100, %96
br label %109
109: ; preds = %108, %86
br label %76
110: ; preds = %76
%111 = load i32*, i32** %12
%112 = call i32 @fclose(i32* %111)
%113 = load i32*, i32** %15
%114 = call i32 @fclose(i32* %113)
%115 = load i32, i32* %17
%116 = icmp ne i32 %115, 0
br i1 %116, label %123, label %117
117: ; preds = %110
%118 = load i32, i32* @stderr
%119 = load i8*, i8** %7
%120 = load i8*, i8** %6
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %119, i8* %120)
%122 = call i32 @remove(i8* %63)
store i32 1, i32* %3
store i32 1, i32* %16
br label %135
123: ; preds = %110
%124 = load i8*, i8** %6
%125 = call i64 @rename(i8* %63, i8* %124)
%126 = icmp ne i64 %125, 0
br i1 %126, label %127, label %134
127: ; preds = %123
%128 = load i32, i32* @stderr
%129 = load i8*, i8** %6
%130 = load i32, i32* @errno
%131 = call i8* @strerror(i32 %130)
%132 = call i32 (i32, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %63, i8* %129, i8* %131)
%133 = call i32 @remove(i8* %63)
store i32 1, i32* %3
store i32 1, i32* %16
br label %135
134: ; preds = %123
store i32 0, i32* %3
store i32 1, i32* %16
br label %135
135: ; preds = %134, %127, %117, %70
%136 = load i8*, i8** %13
br label %137
137: ; preds = %135, %53, %40, %33
%138 = load i32, i32* %3
ret i32 %138
}

LLVM IR (-O2):
@.str = [19 x i8] c"/system/build.prop\00"
@.str.1 = [21 x i8] c"ro.build.fingerprint\00"
@.str.2 = [7 x i8] c"f:p:rn\00"
@optarg = global i8* null
@optind = global i32 0
@stderr = global i32 0
@.str.3 = [267 x i8] c"usage: add-property-tag [flags] tag-to-add\0Aflags: -f /dir/file.prop (default /system/build.prop)\0A -p prop.name (default ro.build.fingerprint)\0A -r (if set, remove the tag rather than adding it)\0A -n (if set, add and increment a number after the tag)\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [19 x i8] c"can't read %s: %s\0A\00"
@errno = global i32 0
@PATH_MAX = global i32 0
@.str.6 = [7 x i8] c"%s.tmp\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [20 x i8] c"can't write %s: %s\0A\00"
@.str.9 = [29 x i8] c"property %s not found in %s\0A\00"
@.str.10 = [27 x i8] c"can't rename %s to %s: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [4096 x i8]
br label %4
4: ; preds = %18, %2
%5 = phi i32 [ 0, %2 ], [ 1, %18 ]
%6 = phi i32 [ 0, %2 ], [ %10, %18 ]
%7 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %2 ], [ %14, %18 ]
%8 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %2 ], [ %17, %18 ]
br label %9
9: ; preds = %18, %4
%10 = phi i32 [ %6, %4 ], [ 1, %18 ]
%11 = phi i8* [ %7, %4 ], [ %14, %18 ]
%12 = phi i8* [ %8, %4 ], [ %17, %18 ]
br label %13
13: ; preds = %9, %22
%14 = phi i8* [ %11, %9 ], [ %23, %22 ]
%15 = phi i8* [ %12, %9 ], [ %17, %22 ]
br label %16
16: ; preds = %13, %20
%17 = phi i8* [ %15, %13 ], [ %21, %20 ]
br label %18
18: ; preds = %16, %18
%19 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
switch i32 %19, label %18 [
i32 -1, label %24
i32 102, label %20
i32 112, label %22
i32 114, label %9
i32 110, label %4
i32 63, label %100
]
20: ; preds = %18
%21 = load i8*, i8** @optarg
br label %16
22: ; preds = %18
%23 = load i8*, i8** @optarg
br label %13
24: ; preds = %18
%25 = load i32, i32* @optind
%26 = add nsw i32 %25, 1
%27 = icmp eq i32 %26, %0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([267 x i8], [267 x i8]* @.str.3, i64 0, i64 0))
br label %100
31: ; preds = %24
%32 = sext i32 %25 to i64
%33 = getelementptr inbounds i8*, i8** %1, i64 %32
%34 = load i8*, i8** %33
%35 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = tail call i8* @strerror(i32 %39)
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %17, i8* %40)
br label %100
42: ; preds = %31
%43 = load i32, i32* @PATH_MAX
%44 = zext i32 %43 to i64
%45 = tail call i8* @llvm.stacksave()
%46 = alloca i8, i64 %44
%47 = call i32 @snprintf(i8* %46, i32 %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %17)
%48 = call i32* @fopen(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %55
50: ; preds = %42
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %46, i8* %53)
br label %98
55: ; preds = %42
%56 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%57 = call i64 @fgets(i8* %56, i32 4096, i32* %35)
%58 = icmp eq i64 %57, 0
br i1 %58, label %78, label %59
59: ; preds = %55
%60 = icmp eq i32 %10, 0
br label %61
61: ; preds = %59, %74
%62 = phi i32 [ 0, %59 ], [ %75, %74 ]
%63 = call i32 @should_tag(i8* %56, i8* %14)
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = call i32 @fputs(i8* %56, i32* %48)
br label %74
67: ; preds = %61
%68 = call i32 @remove_tag(i8* %56, i8* %34)
br i1 %60, label %71, label %69
69: ; preds = %67
%70 = call i32 @fputs(i8* %56, i32* %48)
br label %74
71: ; preds = %67
%72 = add nsw i32 %68, %5
%73 = call i32 @write_tagged(i32* %48, i8* %56, i8* %34, i32 %72)
br label %74
74: ; preds = %69, %71, %65
%75 = phi i32 [ %62, %65 ], [ 1, %71 ], [ 1, %69 ]
%76 = call i64 @fgets(i8* %56, i32 4096, i32* %35)
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %61
78: ; preds = %74, %55
%79 = phi i32 [ 0, %55 ], [ %75, %74 ]
%80 = call i32 @fclose(i32* %35)
%81 = call i32 @fclose(i32* %48)
%82 = icmp eq i32 %79, 0
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %14, i8* %17)
br label %94
86: ; preds = %78
%87 = call i64 @rename(i8* %46, i8* %17)
%88 = icmp eq i64 %87, 0
br i1 %88, label %96, label %89
89: ; preds = %86
%90 = load i32, i32* @stderr
%91 = load i32, i32* @errno
%92 = call i8* @strerror(i32 %91)
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %46, i8* %17, i8* %92)
br label %94
94: ; preds = %83, %89
%95 = call i32 @remove(i8* %46)
br label %96
96: ; preds = %94, %86
%97 = phi i32 [ 0, %86 ], [ 1, %94 ]
br label %98
98: ; preds = %96, %50
%99 = phi i32 [ 1, %50 ], [ %97, %96 ]
br label %100
100: ; preds = %18, %37, %98, %28
%101 = phi i32 [ 2, %28 ], [ 1, %37 ], [ %99, %98 ], [ 2, %18 ]
ret i32 %101
}