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

/* Variables and functions */
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void getstat(char *s) {
  time_t tm;
  FILE *pipe = popen("service ssh status", "r");
  if (!pipe) {
    strcpy(s, "ERROR on command");
    return;
  }
  char buf[128] = "...";
  fgets(buf, 128, pipe);
  tm = time(NULL);
  sprintf(s, "[%s] %s", ctime(&tm), buf);
  while (!feof(pipe)) {
    fgets(buf, 128, pipe);
  }
  pclose(pipe);
  return;
}


x86 assembly (clang, -O0):
<getstat>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe5a(%rip),%rdi
lea    0xe66(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d6 <getstat+0x46>
mov    -0x8(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1291 <getstat+0x101>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
movb   $0x2e,-0xa0(%rbp)
movb   $0x2e,-0x9f(%rbp)
movb   $0x2e,-0x9e(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0xa8(%rbp),%rdi
mov    %rax,%rdx
lea    -0xa0(%rbp),%rcx
lea    0xddb(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    126e <getstat+0xde>
jmp    1288 <getstat+0xf8>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
jmp    1250 <getstat+0xc0>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getstat>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rdi,%r14
lea    0xe6a(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1090 <popen@plt>
test   %rax,%rax
je     1271 <getstat+0xf1>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movw   $0x2e2e,0x10(%rsp)
movb   $0x2e,0x12(%rsp)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <ctime@plt>
lea    0xe0d(%rip),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
mov    %r15,%rcx
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    125c <getstat+0xdc>
lea    0x10(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1240 <getstat+0xc0>
mov    %rbx,%rdi
call   1050 <pclose@plt>
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd9d(%rip),%rsi
mov    %r14,%rdi
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"service ssh status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"ERROR on command\00"
@.str.3 = [8 x i8] c"[%s] %s\00"
define void @getstat(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [128 x i8]
store i8* %0, i8** %2
%6 = 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* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %38
12: ; preds = %1
%13 = bitcast [128 x i8]* %5 to i8*
%14 = bitcast i8* %13 to [128 x i8]*
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i32 0, i32 0
store i8 46, i8* %15
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i32 0, i32 1
store i8 46, i8* %16
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i32 0, i32 2
store i8 46, i8* %17
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%19 = load i32*, i32** %4
%20 = call i32 @fgets(i8* %18, i32 128, i32* %19)
%21 = call i32 @time(i32* null)
store i32 %21, i32* %3
%22 = load i8*, i8** %2
%23 = call i8* @ctime(i32* %3)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%25 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %23, i8* %24)
br label %26
26: ; preds = %31, %12
%27 = load i32*, i32** %4
%28 = call i32 @feof(i32* %27)
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%33 = load i32*, i32** %4
%34 = call i32 @fgets(i8* %32, i32 128, i32* %33)
br label %26
35: ; preds = %26
%36 = load i32*, i32** %4
%37 = call i32 @pclose(i32* %36)
br label %38
38: ; preds = %35, %9
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"service ssh status\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"ERROR on command\00"
@.str.3 = [8 x i8] c"[%s] %s\00"
define void @getstat(i8* %0) {
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = bitcast i32* %2 to i8*
%5 = 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))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %25
9: ; preds = %1
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
store i8 46, i8* %10
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 1
store i8 46, i8* %11
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 2
store i8 46, i8* %12
%13 = call i32 @fgets(i8* %10, i32 128, i32* %5)
%14 = call i32 @time(i32* null)
store i32 %14, i32* %2
%15 = call i8* @ctime(i32* %2)
%16 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %10)
%17 = call i32 @feof(i32* %5)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %9, %19
%20 = call i32 @fgets(i8* %10, i32 128, i32* %5)
%21 = call i32 @feof(i32* %5)
%22 = icmp eq i32 %21, 0
br i1 %22, label %19, label %23
23: ; preds = %19, %9
%24 = call i32 @pclose(i32* %5)
br label %25
25: ; preds = %23, %7
ret void
}