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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int get_time_now(char *str) {
  FILE *ps;
  char buf[32] = {0};
  if ((ps = popen("date +%Y%m%d%H%M%S", "r")) == NULL)
    return 1;
  fgets(buf, sizeof(buf), ps);
  sprintf(str, "%s", buf);
  pclose(ps);
  return 0;
}


x86 assembly (clang, -O0):
<get_time_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    0xe8d(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1199 <get_time_now+0x49>
movl   $0x1,-0x4(%rbp)
jmp    11cf <get_time_now+0x7f>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x20,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe5b(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time_now>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xea1(%rip),%rdi
lea    0xead(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     119d <get_time_now+0x5d>
mov    %rax,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x20,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
jmp    11a2 <get_time_now+0x62>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"date +%Y%m%d%H%M%S\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @get_time_now(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [32 x i8]
store i8* %0, i8** %3
%6 = bitcast [32 x i8]* %5 to i8*
%7 = call i32* @popen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 1, i32* %2
br label %19
10: ; preds = %1
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%12 = load i32*, i32** %4
%13 = call i32 @fgets(i8* %11, i32 32, i32* %12)
%14 = load i8*, i8** %3
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32*, i32** %4
%18 = call i32 @pclose(i32* %17)
store i32 0, i32* %2
br label %19
19: ; preds = %10, %9
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@.str = [19 x i8] c"date +%Y%m%d%H%M%S\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_time_now(i8* %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @popen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = call i32 @fgets(i8* %3, i32 32, i32* %4)
%8 = call i8* @strcpy(i8* dereferenceable(1) %0, i8* %3)
%9 = call i32 @pclose(i32* %4)
br label %10
10: ; preds = %1, %6
%11 = phi i32 [ 0, %6 ], [ 1, %1 ]
ret i32 %11
}