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

/* Variables and functions */
int /*<<< orphan*/ getcwd(char *, int);
int set_logpath(char *);
int /*<<< orphan*/ systemlog(int, char *);
int put_default_logpath() {
  int success = 0;
  char workdir[1024];
  systemlog(3, "put_default_logpath");
  {
    if (!getcwd(workdir, sizeof(workdir))) {
      systemlog(1, "WARNING: put_default_logpath: could not get current "
                   "workdir, redirecting to /tmp");
      success = set_logpath("/tmp");
    } else {
      success = set_logpath(workdir);
    }
  }
  if (success > 0)
    systemlog(93, "\t[DONE]");
  else
    systemlog(93, "\t[FAILD]");
  return success;
}


x86 assembly (clang, -O0):
<put_default_logpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3,%edi
lea    0xeb2(%rip),%rsi
call   1030 <systemlog@plt>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1040 <getcwd@plt>
cmp    $0x0,%eax
jne    1192 <put_default_logpath+0x62>
mov    $0x1,%edi
lea    0xe9b(%rip),%rsi
call   1030 <systemlog@plt>
lea    0xedb(%rip),%rdi
call   1050 <set_logpath@plt>
mov    %eax,-0x4(%rbp)
jmp    11a1 <put_default_logpath+0x71>
lea    -0x410(%rbp),%rdi
call   1050 <set_logpath@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    11c1 <put_default_logpath+0x91>
mov    $0x5d,%edi
lea    0xeae(%rip),%rsi
call   1030 <systemlog@plt>
jmp    11d2 <put_default_logpath+0xa2>
mov    $0x5d,%edi
lea    0xea0(%rip),%rsi
call   1030 <systemlog@plt>
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_default_logpath>:
push   %rbx
sub    $0x400,%rsp
lea    0xec1(%rip),%rsi
mov    $0x3,%edi
call   1030 <systemlog@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
call   1040 <getcwd@plt>
test   %eax,%eax
je     115f <put_default_logpath+0x2f>
mov    %rsp,%rdi
jmp    1177 <put_default_logpath+0x47>
lea    0xeae(%rip),%rsi
mov    $0x1,%edi
call   1030 <systemlog@plt>
lea    0xee9(%rip),%rdi
call   1050 <set_logpath@plt>
mov    %eax,%ebx
test   %eax,%eax
lea    0xede(%rip),%rax
lea    0xedf(%rip),%rsi
cmovg  %rax,%rsi
mov    $0x5d,%edi
call   1030 <systemlog@plt>
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"put_default_logpath\00"
@.str.1 = [81 x i8] c"WARNING: put_default_logpath: could not get current workdir, redirecting to /tmp\00"
@.str.2 = [5 x i8] c"/tmp\00"
@.str.3 = [8 x i8] c"\09[DONE]\00"
@.str.4 = [9 x i8] c"\09[FAILD]\00"
define i32 @put_default_logpath() {
%1 = alloca i32
%2 = alloca [1024 x i8]
store i32 0, i32* %1
%3 = call i32 @systemlog(i32 3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = call i32 @getcwd(i8* %4, i32 1024)
%6 = icmp ne i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i32 @systemlog(i32 1, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @set_logpath(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 %9, i32* %1
br label %13
10: ; preds = %0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%12 = call i32 @set_logpath(i8* %11)
store i32 %12, i32* %1
br label %13
13: ; preds = %10, %7
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @systemlog(i32 93, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %20
18: ; preds = %13
%19 = call i32 @systemlog(i32 93, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [20 x i8] c"put_default_logpath\00"
@.str.1 = [81 x i8] c"WARNING: put_default_logpath: could not get current workdir, redirecting to /tmp\00"
@.str.2 = [5 x i8] c"/tmp\00"
@.str.3 = [8 x i8] c"\09[DONE]\00"
@.str.4 = [9 x i8] c"\09[FAILD]\00"
define i32 @put_default_logpath() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @systemlog(i32 3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @getcwd(i8* %2, i32 1024)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @systemlog(i32 1, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @set_logpath(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %11
9: ; preds = %0
%10 = call i32 @set_logpath(i8* %2)
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ %10, %9 ], [ %8, %6 ]
%13 = icmp sgt i32 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0)
%15 = call i32 @systemlog(i32 93, i8* %14)
ret i32 %12
}