#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 st_size;
};
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ entry;
typedef int /*<<< orphan*/ cmd;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ InsertInPrefsFile(char *, char *, size_t, char *);
int MakeNewPrefsFile(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
int stat(char *, struct stat *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ system(char *);
int main() {
  char path[200];
  char cmd[500];
  char entry[500];
  struct stat fileinfo;
  FILE *fil = NULL;
  char *home;
  size_t filebuflen;
  size_t filelen;
  char *filebuf = NULL;
  int r;
  home = getenv("HOME");
  strncpy(cmd, "/bin/mkdir -p ", sizeof(cmd));
  strncat(cmd, home, sizeof(cmd));
  strncat(cmd, "/.MacOSX", sizeof(cmd));
  cmd[sizeof(cmd) - 1] = '\0';
  system(cmd);
  strncpy(cmd, "/bin/test -d ", sizeof(cmd));
  strncat(cmd, home, sizeof(cmd));
  strncat(cmd, "/Library/OOo.default || /bin/cp -r /usr/local/lib/OOo.default ",
          sizeof(cmd));
  strncat(cmd, home, sizeof(cmd));
  strncat(cmd, "/Library/OOo.default", sizeof(cmd));
  cmd[sizeof(cmd) - 1] = '\0';
  system(cmd);
  strncpy(cmd, "/bin/chmod 600 ", sizeof(cmd));
  strncat(cmd, home, sizeof(cmd));
  strncat(cmd, "/Library/OOo.default/*", sizeof(cmd));
  cmd[sizeof(cmd) - 1] = '\0';
  system(cmd);
  strncpy(entry, "\t<key>MOZILLA_CERTIFICATE_FOLDER</key>\n", sizeof(entry));
  strncat(entry, "\t<string>", sizeof(entry));
  strncat(entry, home, sizeof(entry));
  strncat(entry, "/Library/OOo.default</string>\n", sizeof(entry));
  entry[sizeof(entry) - 1] = '\0';
  strncpy(path, home, sizeof(path));
  strncat(path, "/.MacOSX/environment.plist", sizeof(path));
  path[sizeof(path) - 1] = '\0';
  r = stat(path, &fileinfo);
  if (r != 0)
    return MakeNewPrefsFile(path, entry);
  fil = fopen(path, "r");
  if (fil == NULL)
    return MakeNewPrefsFile(path, entry);
  r = -1;
  filebuflen = fileinfo.st_size + sizeof(entry) + 10;
  if (filebuflen < fileinfo.st_size)
    goto cleanup;
  filebuf = (char *)malloc(filebuflen);
  if (filebuf == NULL)
    goto cleanup;
  filelen = fread(filebuf, 1, fileinfo.st_size, fil);
  filebuf[filelen] = '\0';
  if (strstr(filebuf, "OOo.default") != NULL) {
    r = 0;
    goto cleanup;
  }
  if (strstr(filebuf, "MOZILLA_CERTIFICATE_FOLDER") != NULL) {
    printf("*******************************************************************"
           "************\n");
    printf("Another MOZILLA_CERTIFICATE_FOLDER environment variable has "
           "already been set\n");
    printf("in file \"%s\"\n", path);
    printf("So it looks like support for another smart card has already been "
           "configured\n");
    printf("this way. Pls. use the manual procedure to configure OOo for both "
           "smart cards\n");
    printf("*******************************************************************"
           "************\n");
    goto cleanup;
  }
  fclose(fil);
  fil = NULL;
  InsertInPrefsFile(path, filebuf, filebuflen, entry);
cleanup:
  if (fil != NULL)
    fclose(fil);
  if (filebuf != NULL)
    free(filebuf);
  return r;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x510,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x4e0(%rbp)
movq   $0x0,-0x500(%rbp)
lea    0xdf1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x4e8(%rbp)
lea    -0x2d0(%rbp),%rdi
lea    0xddc(%rip),%rsi
mov    $0x1f4,%edx
call   1050 <strncpy@plt>
lea    -0x2d0(%rbp),%rdi
mov    -0x4e8(%rbp),%rsi
mov    $0x1f4,%edx
call   10b0 <strncat@plt>
lea    -0x2d0(%rbp),%rdi
lea    0xdbb(%rip),%rsi
mov    $0x1f4,%edx
call   10b0 <strncat@plt>
movb   $0x0,-0xdd(%rbp)
lea    -0x2d0(%rbp),%rdi
call   1090 <system@plt>
lea    -0x2d0(%rbp),%rdi
lea    0xd99(%rip),%rsi
mov    $0x1f4,%edx
call   1050 <strncpy@plt>
lea    -0x2d0(%rbp),%rdi
mov    -0x4e8(%rbp),%rsi
mov    $0x1f4,%edx
call   10b0 <strncat@plt>
lea    -0x2d0(%rbp),%rdi
lea    0xd77(%rip),%rsi
mov    $0x1f4,%edx
call   10b0 <strncat@plt>
lea    -0x2d0(%rbp),%rdi
mov    -0x4e8(%rbp),%rsi
mov    $0x1f4,%edx
call   10b0 <strncat@plt>
lea    -0x2d0(%rbp),%rdi
lea    0xd86(%rip),%rsi
mov    $0x1f4,%edx
call   10b0 <strncat@plt>
movb   $0x0,-0xdd(%rbp)
lea    -0x2d0(%rbp),%rdi
call   1090 <system@plt>
lea    -0x2d0(%rbp),%rdi
lea    0xd70(%rip),%rsi
mov    $0x1f4,%edx
call   1050 <strncpy@plt>
lea    -0x2d0(%rbp),%rdi
mov    -0x4e8(%rbp),%rsi
mov    $0x1f4,%edx
call   10b0 <strncat@plt>
lea    -0x2d0(%rbp),%rdi
lea    0xd50(%rip),%rsi
mov    $0x1f4,%edx
call   10b0 <strncat@plt>
movb   $0x0,-0xdd(%rbp)
lea    -0x2d0(%rbp),%rdi
call   1090 <system@plt>
lea    -0x4d0(%rbp),%rdi
lea    0xd3c(%rip),%rsi
mov    $0x1f4,%edx
call   1050 <strncpy@plt>
lea    -0x4d0(%rbp),%rdi
lea    0xd4c(%rip),%rsi
mov    $0x1f4,%edx
call   10b0 <strncat@plt>
lea    -0x4d0(%rbp),%rdi
mov    -0x4e8(%rbp),%rsi
mov    $0x1f4,%edx
call   10b0 <strncat@plt>
lea    -0x4d0(%rbp),%rdi
lea    0xd26(%rip),%rsi
mov    $0x1f4,%edx
call   10b0 <strncat@plt>
movb   $0x0,-0x2dd(%rbp)
lea    -0xd0(%rbp),%rdi
mov    -0x4e8(%rbp),%rsi
mov    $0xc8,%edx
call   1050 <strncpy@plt>
lea    -0xd0(%rbp),%rdi
lea    0xd0e(%rip),%rsi
mov    $0xc8,%edx
call   10b0 <strncat@plt>
movb   $0x0,-0x9(%rbp)
lea    -0xd0(%rbp),%rdi
lea    -0x4d8(%rbp),%rsi
call   10c0 <stat@plt>
mov    %eax,-0x504(%rbp)
cmpl   $0x0,-0x504(%rbp)
je     1438 <main+0x258>
lea    -0xd0(%rbp),%rdi
lea    -0x4d0(%rbp),%rsi
call   1060 <MakeNewPrefsFile@plt>
mov    %eax,-0x4(%rbp)
jmp    1635 <main+0x455>
lea    -0xd0(%rbp),%rdi
lea    0xccc(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x4e0(%rbp)
cmpq   $0x0,-0x4e0(%rbp)
jne    147b <main+0x29b>
lea    -0xd0(%rbp),%rdi
lea    -0x4d0(%rbp),%rsi
call   1060 <MakeNewPrefsFile@plt>
mov    %eax,-0x4(%rbp)
jmp    1635 <main+0x455>
movl   $0xffffffff,-0x504(%rbp)
ff ff ff
movslq -0x4d8(%rbp),%rax
add    $0x1f4,%rax
add    $0xa,%rax
mov    %rax,-0x4f0(%rbp)
mov    -0x4f0(%rbp),%rax
movslq -0x4d8(%rbp),%rcx
cmp    %rcx,%rax
jae    14b9 <main+0x2d9>
jmp    15f8 <main+0x418>
mov    -0x4f0(%rbp),%rdi
call   10d0 <malloc@plt>
mov    %rax,-0x500(%rbp)
cmpq   $0x0,-0x500(%rbp)
jne    14df <main+0x2ff>
jmp    15f8 <main+0x418>
mov    -0x500(%rbp),%rdi
movslq -0x4d8(%rbp),%rdx
mov    -0x4e0(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fread@plt>
mov    %rax,-0x4f8(%rbp)
mov    -0x500(%rbp),%rax
mov    -0x4f8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x500(%rbp),%rdi
lea    0xb4e(%rip),%rsi
call   1100 <strstr@plt>
cmp    $0x0,%rax
je     1543 <main+0x363>
movl   $0x0,-0x504(%rbp)
jmp    15f8 <main+0x418>
mov    -0x500(%rbp),%rdi
lea    0xbc3(%rip),%rsi
call   1100 <strstr@plt>
cmp    $0x0,%rax
je     15c0 <main+0x3e0>
lea    0xbc8(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    0xc0b(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    -0xd0(%rbp),%rsi
lea    0xc44(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    0xc44(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    0xc83(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
lea    0xb7b(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    15f8 <main+0x418>
mov    -0x4e0(%rbp),%rdi
call   1080 <fclose@plt>
movq   $0x0,-0x4e0(%rbp)
lea    -0xd0(%rbp),%rdi
mov    -0x500(%rbp),%rsi
mov    -0x4f0(%rbp),%rdx
lea    -0x4d0(%rbp),%rcx
call   10e0 <InsertInPrefsFile@plt>
cmpq   $0x0,-0x4e0(%rbp)
je     1612 <main+0x432>
mov    -0x4e0(%rbp),%rdi
call   1080 <fclose@plt>
cmpq   $0x0,-0x500(%rbp)
je     162c <main+0x44c>
mov    -0x500(%rbp),%rdi
call   1040 <free@plt>
mov    -0x504(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x510,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x4d8,%rsp
lea    0xdfc(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
lea    0xdf2(%rip),%rsi
lea    0x2e0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1f4,%edx
call   1050 <strncpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1f4,%edx
call   10c0 <strncat@plt>
lea    0xdd5(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1f4,%edx
call   10c0 <strncat@plt>
movb   $0x0,0x4d3(%rsp)
mov    %rbx,%rdi
call   10a0 <system@plt>
lea    0xdba(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1f4,%edx
call   1050 <strncpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1f4,%edx
call   10c0 <strncat@plt>
lea    0xda4(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1f4,%edx
call   10c0 <strncat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1f4,%edx
call   10c0 <strncat@plt>
lea    0xdbf(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1f4,%edx
call   10c0 <strncat@plt>
movb   $0x0,0x4d3(%rsp)
mov    %rbx,%rdi
call   10a0 <system@plt>
lea    0xdb0(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1f4,%edx
call   1050 <strncpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1f4,%edx
call   10c0 <strncat@plt>
lea    0xd9c(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1f4,%edx
call   10c0 <strncat@plt>
movb   $0x0,0x4d3(%rsp)
mov    %rbx,%rdi
call   10a0 <system@plt>
lea    0xd8f(%rip),%rsi
lea    0xe0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1f4,%edx
call   1050 <strncpy@plt>
lea    0xd9b(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1f4,%edx
call   10c0 <strncat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1f4,%edx
call   10c0 <strncat@plt>
lea    0xd81(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1f4,%edx
call   10c0 <strncat@plt>
movb   $0x0,0x2d3(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xc8,%edx
call   1050 <strncpy@plt>
lea    0xd6f(%rip),%rsi
mov    %rbx,%rdi
mov    $0xc8,%edx
call   10c0 <strncat@plt>
movb   $0x0,0xd7(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10d0 <stat@plt>
test   %eax,%eax
je     13d2 <main+0x1e2>
lea    0x10(%rsp),%rdi
lea    0xe0(%rsp),%rsi
call   1060 <MakeNewPrefsFile@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x4d8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd39(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1100 <fopen@plt>
test   %rax,%rax
je     13ae <main+0x1be>
mov    %rax,%rbx
movslq 0x8(%rsp),%rbp
cmp    $0xfffffffffffffe01,%rbp
ja     14c2 <main+0x2d2>
lea    0x1fe(%rbp),%r15
mov    %r15,%rdi
call   10e0 <malloc@plt>
test   %rax,%rax
je     14c2 <main+0x2d2>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1080 <fread@plt>
movb   $0x0,(%r14,%rax,1)
lea    0xc3c(%rip),%rsi
mov    %r14,%rdi
call   1110 <strstr@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    14ad <main+0x2bd>
lea    0xcc7(%rip),%rsi
mov    %r14,%rdi
call   1110 <strstr@plt>
test   %rax,%rax
je     14d4 <main+0x2e4>
lea    0xdc3(%rip),%rbp
mov    %rbp,%rdi
call   1070 <puts@plt>
lea    0xccd(%rip),%rdi
call   1070 <puts@plt>
lea    0xcb3(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   10b0 <printf@plt>
lea    0xcfb(%rip),%rdi
call   1070 <puts@plt>
lea    0xd3b(%rip),%rdi
call   1070 <puts@plt>
mov    %rbp,%rdi
call   1070 <puts@plt>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1090 <fclose@plt>
mov    %r14,%rdi
call   1040 <free@plt>
jmp    13c2 <main+0x1d2>
mov    %rbx,%rdi
call   1090 <fclose@plt>
mov    $0xffffffff,%ebp
jmp    13c2 <main+0x1d2>
mov    %rbx,%rdi
call   1090 <fclose@plt>
lea    0x10(%rsp),%rdi
lea    0xe0(%rsp),%rcx
mov    %r14,%rsi
mov    %r15,%rdx
call   10f0 <InsertInPrefsFile@plt>
mov    $0xffffffff,%ebp
jmp    14b5 <main+0x2c5>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"HOME\00"
@.str.1 = [15 x i8] c"/bin/mkdir -p \00"
@.str.2 = [9 x i8] c"/.MacOSX\00"
@.str.3 = [14 x i8] c"/bin/test -d \00"
@.str.4 = [63 x i8] c"/Library/OOo.default || /bin/cp -r /usr/local/lib/OOo.default \00"
@.str.5 = [21 x i8] c"/Library/OOo.default\00"
@.str.6 = [16 x i8] c"/bin/chmod 600 \00"
@.str.7 = [23 x i8] c"/Library/OOo.default/*\00"
@.str.8 = [40 x i8] c"\09<key>MOZILLA_CERTIFICATE_FOLDER</key>\0A\00"
@.str.9 = [10 x i8] c"\09<string>\00"
@.str.10 = [31 x i8] c"/Library/OOo.default</string>\0A\00"
@.str.11 = [27 x i8] c"/.MacOSX/environment.plist\00"
@.str.12 = [2 x i8] c"r\00"
@.str.13 = [12 x i8] c"OOo.default\00"
@.str.14 = [27 x i8] c"MOZILLA_CERTIFICATE_FOLDER\00"
@.str.15 = [81 x i8] c"*******************************************************************************\0A\00"
@.str.16 = [78 x i8] c"Another MOZILLA_CERTIFICATE_FOLDER environment variable has already been set\0A\00"
@.str.17 = [14 x i8] c"in file \22%s\22\0A\00"
@.str.18 = [77 x i8] c"So it looks like support for another smart card has already been configured\0A\00"
@.str.19 = [79 x i8] c"this way. Pls. use the manual procedure to configure OOo for both smart cards\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [200 x i8]
%3 = alloca [500 x i8]
%4 = alloca [500 x i8]
%5 = alloca %struct.stat
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %1
store i32* null, i32** %6
store i8* null, i8** %10
%12 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %7
%13 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%14 = call i32 @strncpy(i8* %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 500)
%15 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%16 = load i8*, i8** %7
%17 = call i32 @strncat(i8* %15, i8* %16, i32 500)
%18 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%19 = call i32 @strncat(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 500)
%20 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 499
store i8 0, i8* %20
%21 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%22 = call i32 @system(i8* %21)
%23 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%24 = call i32 @strncpy(i8* %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 500)
%25 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%26 = load i8*, i8** %7
%27 = call i32 @strncat(i8* %25, i8* %26, i32 500)
%28 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%29 = call i32 @strncat(i8* %28, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0), i32 500)
%30 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%31 = load i8*, i8** %7
%32 = call i32 @strncat(i8* %30, i8* %31, i32 500)
%33 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%34 = call i32 @strncat(i8* %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 500)
%35 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 499
store i8 0, i8* %35
%36 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%37 = call i32 @system(i8* %36)
%38 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%39 = call i32 @strncpy(i8* %38, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 500)
%40 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%41 = load i8*, i8** %7
%42 = call i32 @strncat(i8* %40, i8* %41, i32 500)
%43 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%44 = call i32 @strncat(i8* %43, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 500)
%45 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 499
store i8 0, i8* %45
%46 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%47 = call i32 @system(i8* %46)
%48 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%49 = call i32 @strncpy(i8* %48, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i32 500)
%50 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%51 = call i32 @strncat(i8* %50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 500)
%52 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%53 = load i8*, i8** %7
%54 = call i32 @strncat(i8* %52, i8* %53, i32 500)
%55 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%56 = call i32 @strncat(i8* %55, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 500)
%57 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 499
store i8 0, i8* %57
%58 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%59 = load i8*, i8** %7
%60 = call i32 @strncpy(i8* %58, i8* %59, i32 200)
%61 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%62 = call i32 @strncat(i8* %61, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i32 200)
%63 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 199
store i8 0, i8* %63
%64 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%65 = call i32 @stat(i8* %64, %struct.stat* %5)
store i32 %65, i32* %11
%66 = load i32, i32* %11
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %0
%69 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%70 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%71 = call i32 @MakeNewPrefsFile(i8* %69, i8* %70)
store i32 %71, i32* %1
br label %148
72: ; preds = %0
%73 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%74 = call i32* @fopen(i8* %73, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
store i32* %74, i32** %6
%75 = load i32*, i32** %6
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %81
77: ; preds = %72
%78 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%79 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%80 = call i32 @MakeNewPrefsFile(i8* %78, i8* %79)
store i32 %80, i32* %1
br label %148
81: ; preds = %72
store i32 -1, i32* %11
%82 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%83 = load i32, i32* %82
%84 = sext i32 %83 to i64
%85 = add i64 %84, 500
%86 = add i64 %85, 10
store i64 %86, i64* %8
%87 = load i64, i64* %8
%88 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%89 = load i32, i32* %88
%90 = sext i32 %89 to i64
%91 = icmp ult i64 %87, %90
br i1 %91, label %92, label %93
92: ; preds = %81
br label %134
93: ; preds = %81
%94 = load i64, i64* %8
%95 = call i64 @malloc(i64 %94)
%96 = inttoptr i64 %95 to i8*
store i8* %96, i8** %10
%97 = load i8*, i8** %10
%98 = icmp eq i8* %97, null
br i1 %98, label %99, label %100
99: ; preds = %93
br label %134
100: ; preds = %93
%101 = load i8*, i8** %10
%102 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%103 = load i32, i32* %102
%104 = sext i32 %103 to i64
%105 = load i32*, i32** %6
%106 = call i64 @fread(i8* %101, i32 1, i64 %104, i32* %105)
store i64 %106, i64* %9
%107 = load i8*, i8** %10
%108 = load i64, i64* %9
%109 = getelementptr inbounds i8, i8* %107, i64 %108
store i8 0, i8* %109
%110 = load i8*, i8** %10
%111 = call i32* @strstr(i8* %110, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0))
%112 = icmp ne i32* %111, null
br i1 %112, label %113, label %114
113: ; preds = %100
store i32 0, i32* %11
br label %134
114: ; preds = %100
%115 = load i8*, i8** %10
%116 = call i32* @strstr(i8* %115, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0))
%117 = icmp ne i32* %116, null
br i1 %117, label %118, label %126
118: ; preds = %114
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.15, i64 0, i64 0))
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.16, i64 0, i64 0))
%121 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.17, i64 0, i64 0), i8* %121)
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.18, i64 0, i64 0))
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.19, i64 0, i64 0))
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.15, i64 0, i64 0))
br label %134
126: ; preds = %114
%127 = load i32*, i32** %6
%128 = call i32 @fclose(i32* %127)
store i32* null, i32** %6
%129 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%130 = load i8*, i8** %10
%131 = load i64, i64* %8
%132 = getelementptr inbounds [500 x i8], [500 x i8]* %4, i64 0, i64 0
%133 = call i32 @InsertInPrefsFile(i8* %129, i8* %130, i64 %131, i8* %132)
br label %134
134: ; preds = %126, %118, %113, %99, %92
%135 = load i32*, i32** %6
%136 = icmp ne i32* %135, null
br i1 %136, label %137, label %140
137: ; preds = %134
%138 = load i32*, i32** %6
%139 = call i32 @fclose(i32* %138)
br label %140
140: ; preds = %137, %134
%141 = load i8*, i8** %10
%142 = icmp ne i8* %141, null
br i1 %142, label %143, label %146
143: ; preds = %140
%144 = load i8*, i8** %10
%145 = call i32 @free(i8* %144)
br label %146
146: ; preds = %143, %140
%147 = load i32, i32* %11
store i32 %147, i32* %1
br label %148
148: ; preds = %146, %77, %68
%149 = load i32, i32* %1
ret i32 %149
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"HOME\00"
@.str.1 = [15 x i8] c"/bin/mkdir -p \00"
@.str.2 = [9 x i8] c"/.MacOSX\00"
@.str.3 = [14 x i8] c"/bin/test -d \00"
@.str.4 = [63 x i8] c"/Library/OOo.default || /bin/cp -r /usr/local/lib/OOo.default \00"
@.str.5 = [21 x i8] c"/Library/OOo.default\00"
@.str.6 = [16 x i8] c"/bin/chmod 600 \00"
@.str.7 = [23 x i8] c"/Library/OOo.default/*\00"
@.str.8 = [40 x i8] c"\09<key>MOZILLA_CERTIFICATE_FOLDER</key>\0A\00"
@.str.9 = [10 x i8] c"\09<string>\00"
@.str.10 = [31 x i8] c"/Library/OOo.default</string>\0A\00"
@.str.11 = [27 x i8] c"/.MacOSX/environment.plist\00"
@.str.12 = [2 x i8] c"r\00"
@.str.13 = [12 x i8] c"OOo.default\00"
@.str.14 = [27 x i8] c"MOZILLA_CERTIFICATE_FOLDER\00"
@.str.17 = [14 x i8] c"in file \22%s\22\0A\00"
@str.20 = [77 x i8] c"Another MOZILLA_CERTIFICATE_FOLDER environment variable has already been set\00"
@str.21 = [76 x i8] c"So it looks like support for another smart card has already been configured\00"
@str.22 = [78 x i8] c"this way. Pls. use the manual procedure to configure OOo for both smart cards\00"
@str.23 = [80 x i8] c"*******************************************************************************\00"
define i32 @main() {
%1 = alloca [200 x i8]
%2 = alloca [500 x i8]
%3 = alloca [500 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%8 = bitcast %struct.stat* %4 to i8*
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @strncpy(i8* %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 500)
%11 = call i32 @strncat(i8* %6, i8* %9, i32 500)
%12 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 500)
%13 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 499
store i8 0, i8* %13
%14 = call i32 @system(i8* %6)
%15 = call i32 @strncpy(i8* %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 500)
%16 = call i32 @strncat(i8* %6, i8* %9, i32 500)
%17 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.4, i64 0, i64 0), i32 500)
%18 = call i32 @strncat(i8* %6, i8* %9, i32 500)
%19 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 500)
store i8 0, i8* %13
%20 = call i32 @system(i8* %6)
%21 = call i32 @strncpy(i8* %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 500)
%22 = call i32 @strncat(i8* %6, i8* %9, i32 500)
%23 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 500)
store i8 0, i8* %13
%24 = call i32 @system(i8* %6)
%25 = call i32 @strncpy(i8* %7, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0), i32 500)
%26 = call i32 @strncat(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 500)
%27 = call i32 @strncat(i8* %7, i8* %9, i32 500)
%28 = call i32 @strncat(i8* %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 500)
%29 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 499
store i8 0, i8* %29
%30 = call i32 @strncpy(i8* %5, i8* %9, i32 200)
%31 = call i32 @strncat(i8* %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i32 200)
%32 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 199
store i8 0, i8* %32
%33 = call i32 @stat(i8* %5, %struct.stat* %4)
%34 = icmp eq i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %0
%36 = call i32 @MakeNewPrefsFile(i8* %5, i8* %7)
br label %78
37: ; preds = %0
%38 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @MakeNewPrefsFile(i8* %5, i8* %7)
br label %78
42: ; preds = %37
%43 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%44 = load i32, i32* %43
%45 = sext i32 %44 to i64
%46 = add nsw i64 %45, 510
%47 = icmp ugt i32 %44, -511
br i1 %47, label %70, label %48
48: ; preds = %42
%49 = call i64 @malloc(i64 %46)
%50 = inttoptr i64 %49 to i8*
%51 = icmp eq i64 %49, 0
br i1 %51, label %70, label %52
52: ; preds = %48
%53 = call i64 @fread(i8* %50, i32 1, i64 %45, i32* %38)
%54 = getelementptr inbounds i8, i8* %50, i64 %53
store i8 0, i8* %54
%55 = call i32* @strstr(i8* %50, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0))
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %72
57: ; preds = %52
%58 = call i32* @strstr(i8* %50, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0))
%59 = icmp eq i32* %58, null
br i1 %59, label %67, label %60
60: ; preds = %57
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @str.23, i64 0, i64 0))
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str.20, i64 0, i64 0))
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.17, i64 0, i64 0), i8* %5)
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str.21, i64 0, i64 0))
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str.22, i64 0, i64 0))
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @str.23, i64 0, i64 0))
br label %72
67: ; preds = %57
%68 = call i32 @fclose(i32* %38)
%69 = call i32 @InsertInPrefsFile(i8* %5, i8* %50, i64 %46, i8* %7)
br label %75
70: ; preds = %48, %42
%71 = call i32 @fclose(i32* %38)
br label %78
72: ; preds = %52, %60
%73 = phi i32 [ 0, %52 ], [ -1, %60 ]
%74 = call i32 @fclose(i32* %38)
br label %75
75: ; preds = %72, %67
%76 = phi i32 [ -1, %67 ], [ %73, %72 ]
%77 = call i32 @free(i8* %50)
br label %78
78: ; preds = %70, %75, %40, %35
%79 = phi i32 [ %36, %35 ], [ %41, %40 ], [ %76, %75 ], [ -1, %70 ]
ret i32 %79
}