#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 */

/* Variables and functions */
char *appendString(char *, char *);
int /*<<< orphan*/ destroyStr(char *);
char *getDirectoryName(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char const *, char *, int /*<<< orphan*/);
char *strstr(char const *, char *);
int /*<<< orphan*/ writeFile(char *, char *, char *);
int main(int argc, const char *argv[]) {
  int i;
  char elfPath[1024] = "", device[100] = "", *ret1, *ret2,
       *parentDirName = NULL, *dirName = NULL;
  for (i = 0; i < argc; i++) {
    ret1 = strstr(argv[i], ".elf");
    ret2 = strstr(argv[i], "--driver=");
    if (ret1 != NULL) {
      if (strcmp(ret1, ".elf") == 0 && ret2 == NULL)
        strcpy(elfPath, argv[i]);
    }
    if (strncmp(argv[i], "STM", strlen("STM")) == 0)
      strcpy(device, argv[i]);
  }
  parentDirName = getDirectoryName((char *)argv[0]);
  if (parentDirName != NULL)
    dirName = appendString(parentDirName, "/ElfLocation.txt");
  else {
    printf("Unable to get directoy\n");
    return 0;
  }
  writeFile(dirName, "w", elfPath);
  writeFile(dirName, "a", device);
  destroyStr(parentDirName);
  destroyStr(dirName);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    -0x490(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1080 <memset@plt>
movq   $0x0,-0x4a8(%rbp)
movq   $0x0,-0x4b0(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1315 <main+0x165>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdd5(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x498(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdbb(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x4a0(%rbp)
cmpq   $0x0,-0x498(%rbp)
je     12ac <main+0xfc>
mov    -0x498(%rbp),%rdi
lea    0xd8e(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12a7 <main+0xf7>
cmpq   $0x0,-0x4a0(%rbp)
jne    12a7 <main+0xf7>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <strcpy@plt>
jmp    12ac <main+0xfc>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x4b8(%rbp)
lea    0xd49(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x4b8(%rbp),%rdi
mov    %eax,%edx
lea    0xd34(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1302 <main+0x152>
lea    -0x490(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <strcpy@plt>
jmp    1307 <main+0x157>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    120c <main+0x5c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <getDirectoryName@plt>
mov    %rax,-0x4a8(%rbp)
cmpq   $0x0,-0x4a8(%rbp)
je     1355 <main+0x1a5>
mov    -0x4a8(%rbp),%rdi
lea    0xccf(%rip),%rsi
call   10c0 <appendString@plt>
mov    %rax,-0x4b0(%rbp)
jmp    136d <main+0x1bd>
lea    0xcc8(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c0 <main+0x210>
mov    -0x4b0(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xcba(%rip),%rsi
call   10a0 <writeFile@plt>
mov    -0x4b0(%rbp),%rdi
lea    -0x490(%rbp),%rdx
lea    0xca2(%rip),%rsi
call   10a0 <writeFile@plt>
mov    -0x4a8(%rbp),%rdi
call   10b0 <destroyStr@plt>
mov    -0x4b0(%rbp),%rdi
call   10b0 <destroyStr@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x478,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x70(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1080 <memset@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
test   %ebp,%ebp
jle    12ae <main+0xfe>
mov    %ebp,%r13d
xor    %r14d,%r14d
lea    0xdfb(%rip),%r15
jmp    1247 <main+0x97>
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx,%r14,8),%rbp
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     12a0 <main+0xf0>
add    $0x1,%r14
cmp    %r14,%r13
je     12ae <main+0xfe>
mov    (%rbx,%r14,8),%rbp
mov    %rbp,%rdi
lea    0xdab(%rip),%rsi
call   10d0 <strstr@plt>
test   %rax,%rax
je     1220 <main+0x70>
mov    %rax,%r12
mov    %rbp,%rdi
lea    0xd99(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,%rbp
mov    %r12,%rdi
lea    0xd82(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    1220 <main+0x70>
test   %rbp,%rbp
jne    1220 <main+0x70>
mov    (%rbx,%r14,8),%rsi
lea    0x70(%rsp),%rdi
call   1050 <strcpy@plt>
jmp    1220 <main+0x70>
nopl   (%rax)
mov    (%rbx,%r14,8),%rsi
mov    %rsp,%rdi
call   1050 <strcpy@plt>
jmp    123e <main+0x8e>
mov    (%rbx),%rdi
call   1030 <getDirectoryName@plt>
test   %rax,%rax
je     1308 <main+0x158>
mov    %rax,%rbx
lea    0xd4e(%rip),%rsi
mov    %rax,%rdi
call   10c0 <appendString@plt>
mov    %rax,%rbp
lea    0xd4d(%rip),%rsi
lea    0x70(%rsp),%rdx
mov    %rax,%rdi
call   10a0 <writeFile@plt>
lea    0xd3b(%rip),%rsi
mov    %rsp,%rdx
mov    %rbp,%rdi
call   10a0 <writeFile@plt>
mov    %rbx,%rdi
call   10b0 <destroyStr@plt>
mov    %rbp,%rdi
call   10b0 <destroyStr@plt>
jmp    1314 <main+0x164>
lea    0xd19(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
add    $0x478,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".elf\00"
@.str.1 = [10 x i8] c"--driver=\00"
@.str.2 = [4 x i8] c"STM\00"
@.str.3 = [17 x i8] c"/ElfLocation.txt\00"
@.str.4 = [24 x i8] c"Unable to get directoy\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [2 x i8] c"a\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca [100 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [1024 x i8]* %7 to i8*
%14 = bitcast [100 x i8]* %8 to i8*
store i8* null, i8** %11
store i8* null, i8** %12
store i32 0, i32* %6
br label %15
15: ; preds = %68, %2
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %71
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i8* @strstr(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %25, i8** %9
%26 = load i8**, i8*** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i8* @strstr(i8* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i8* %31, i8** %10
%32 = load i8*, i8** %9
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %50
34: ; preds = %19
%35 = load i8*, i8** %9
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = load i8*, i8** %10
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%43 = load i8**, i8*** %5
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 @strcpy(i8* %42, i8* %47)
br label %49
49: ; preds = %41, %38, %34
br label %50
50: ; preds = %49, %19
%51 = load i8**, i8*** %5
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%57 = call i64 @strncmp(i8* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %67
59: ; preds = %50
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%61 = load i8**, i8*** %5
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i32 @strcpy(i8* %60, i8* %65)
br label %67
67: ; preds = %59, %50
br label %68
68: ; preds = %67
%69 = load i32, i32* %6
%70 = add nsw i32 %69, 1
store i32 %70, i32* %6
br label %15
71: ; preds = %15
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 0
%74 = load i8*, i8** %73
%75 = call i8* @getDirectoryName(i8* %74)
store i8* %75, i8** %11
%76 = load i8*, i8** %11
%77 = icmp ne i8* %76, null
br i1 %77, label %78, label %81
78: ; preds = %71
%79 = load i8*, i8** %11
%80 = call i8* @appendString(i8* %79, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i8* %80, i8** %12
br label %83
81: ; preds = %71
%82 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %94
83: ; preds = %78
%84 = load i8*, i8** %12
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%86 = call i32 @writeFile(i8* %84, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* %85)
%87 = load i8*, i8** %12
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%89 = call i32 @writeFile(i8* %87, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %88)
%90 = load i8*, i8** %11
%91 = call i32 @destroyStr(i8* %90)
%92 = load i8*, i8** %12
%93 = call i32 @destroyStr(i8* %92)
store i32 0, i32* %3
br label %94
94: ; preds = %83, %81
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@.str = [5 x i8] c".elf\00"
@.str.1 = [10 x i8] c"--driver=\00"
@.str.2 = [4 x i8] c"STM\00"
@.str.3 = [17 x i8] c"/ElfLocation.txt\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [2 x i8] c"a\00"
@str = [23 x i8] c"Unable to get directoy\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %36
8: ; preds = %2
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %33
%11 = phi i64 [ 0, %8 ], [ %34, %33 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = call i8* @strstr(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %25, label %16
16: ; preds = %10
%17 = call i8* @strstr(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%18 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
%20 = icmp eq i8* %17, null
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i8*, i8** %12
%24 = call i32 @strcpy(i8* %5, i8* %23)
br label %25
25: ; preds = %16, %22, %10
%26 = load i8*, i8** %12
%27 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%28 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i8*, i8** %12
%32 = call i32 @strcpy(i8* %6, i8* %31)
br label %33
33: ; preds = %25, %30
%34 = add nuw nsw i64 %11, 1
%35 = icmp eq i64 %34, %9
br i1 %35, label %36, label %10
36: ; preds = %33, %2
%37 = load i8*, i8** %1
%38 = call i8* @getDirectoryName(i8* %37)
%39 = icmp eq i8* %38, null
br i1 %39, label %46, label %40
40: ; preds = %36
%41 = call i8* @appendString(i8* %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 @writeFile(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%43 = call i32 @writeFile(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%44 = call i32 @destroyStr(i8* %38)
%45 = call i32 @destroyStr(i8* %41)
br label %48
46: ; preds = %36
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %48
48: ; preds = %40, %46
ret i32 0
}