#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 */
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
void setPath(char **pPath, const char *sNewPath) {
  char *sPath;
  int nNewPathLength;
  sPath = *pPath;
  if (sPath)
    free(sPath);
  sPath = 0;
  if (sNewPath != 0) {
    printf("%s\n", sNewPath);
    nNewPathLength = strlen(sNewPath);
    sPath = malloc(nNewPathLength + 1);
    if (sPath) {
      strcpy(sPath, sNewPath);
    }
    printf("%s\n", sPath);
  }
  *pPath = sPath;
}


x86 assembly (clang, -O0):
<setPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     117f <setPath+0x2f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e5 <setPath+0x95>
mov    -0x10(%rbp),%rsi
lea    0xe63(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d5 <setPath+0x85>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rsi
lea    0xe20(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setPath>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1168 <setPath+0x18>
call   1030 <free@plt>
test   %r15,%r15
je     11b0 <setPath+0x60>
lea    0xe8c(%rip),%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     119f <setPath+0x4f>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0xe5a(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
jmp    11b2 <setPath+0x62>
xor    %ebx,%ebx
mov    %rbx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define void @setPath(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8** %0, i8*** %3
store i8* %1, i8** %4
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i32 @free(i8* %12)
br label %14
14: ; preds = %11, %2
store i8* null, i8** %5
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %34
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %31
27: ; preds = %17
%28 = load i8*, i8** %5
%29 = load i8*, i8** %4
%30 = call i32 @strcpy(i8* %28, i8* %29)
br label %31
31: ; preds = %27, %17
%32 = load i8*, i8** %5
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %14
%35 = load i8*, i8** %5
%36 = load i8**, i8*** %3
store i8* %35, i8** %36
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @setPath(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @free(i8* %3)
br label %7
7: ; preds = %5, %2
%8 = icmp eq i8* %1, null
br i1 %8, label %19, label %9
9: ; preds = %7
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%11 = tail call i32 @strlen(i8* %1)
%12 = add nsw i32 %11, 1
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = tail call i32 @strcpy(i8* %13, i8* %1)
br label %17
17: ; preds = %15, %9
%18 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %19
19: ; preds = %17, %7
%20 = phi i8* [ %13, %17 ], [ null, %7 ]
store i8* %20, i8** %0
ret void
}