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

/* Variables and functions */
int WEXITSTATUS(int /*<<< orphan*/);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ system(char *);
char *whatis_get(const char *cmd) {
  char *system_str;
  int check_man;
  FILE *f;
  char *desc = NULL;
  int desc_len = 0;
  char ch;
  int i;
  char buf[1024];
  system_str = (char *)malloc(sizeof(char) * (30 + strlen(cmd) + 1));
  sprintf(system_str, "whatis %s >/dev/null 2>/dev/null", cmd);
  check_man = WEXITSTATUS(system(system_str));
  free(system_str);
  if (check_man != 0) {
    return desc;
  }
  system_str = (char *)malloc(sizeof(char) * (39 + strlen(cmd) + 1));
  sprintf(system_str, "whatis %s |head -1 |sed -r -e 's/.* - //'", cmd);
  f = popen(system_str, "r");
  ch = fgetc(f);
  for (i = 0; (ch != '\n') && (ch != '\0'); ++i) {
    buf[i] = ch;
    desc_len += 1;
    ch = fgetc(f);
  }
  buf[i] = '\0';
  desc = (char *)malloc(sizeof(char) * (desc_len + 1));
  strcpy(desc, buf);
  return desc;
}


x86 assembly (clang, -O0):
<whatis_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1e,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <system@plt>
mov    %eax,%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1215 <whatis_get+0x85>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1314 <whatis_get+0x184>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x27,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xddd(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x35(%rbp)
movl   $0x0,-0x3c(%rbp)
movsbl -0x35(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x441(%rbp)
je     1295 <whatis_get+0x105>
movsbl -0x35(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x441(%rbp)
mov    -0x441(%rbp),%al
test   $0x1,%al
jne    12a8 <whatis_get+0x118>
jmp    12d9 <whatis_get+0x149>
mov    -0x35(%rbp),%cl
movslq -0x3c(%rbp),%rax
mov    %cl,-0x440(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x35(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1270 <whatis_get+0xe0>
movslq -0x3c(%rbp),%rax
movb   $0x0,-0x440(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x440(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<whatis_get>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
call   1050 <strlen@plt>
lea    0x1f(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe4b(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
mov    %eax,%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     11e4 <whatis_get+0x54>
xor    %ebx,%ebx
jmp    1265 <whatis_get+0xd5>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x28(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe23(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   10b0 <sprintf@plt>
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <popen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <fgetc@plt>
xor    %ebx,%ebx
test   %al,%al
je     1247 <whatis_get+0xb7>
nopl   0x0(%rax)
cmp    $0xa,%al
je     1247 <whatis_get+0xb7>
mov    %al,(%rsp,%rbx,1)
mov    %r14,%rdi
call   1070 <fgetc@plt>
add    $0x1,%rbx
test   %al,%al
jne    1230 <whatis_get+0xa0>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
add    $0x1,%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"whatis %s >/dev/null 2>/dev/null\00"
@.str.1 = [42 x i8] c"whatis %s |head -1 |sed -r -e 's/.* - //'\00"
@.str.2 = [2 x i8] c"r\00"
define i8* @whatis_get(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32
%11 = alloca [1024 x i8]
store i8* %0, i8** %3
store i8* null, i8** %7
store i32 0, i32* %8
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 30, %13
%15 = add nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = mul i64 1, %16
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = load i8*, i8** %3
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %4
%25 = call i32 @system(i8* %24)
%26 = call i32 @WEXITSTATUS(i32 %25)
store i32 %26, i32* %5
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
%29 = load i32, i32* %5
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %1
%32 = load i8*, i8** %7
store i8* %32, i8** %2
br label %87
33: ; preds = %1
%34 = load i8*, i8** %3
%35 = call i32 @strlen(i8* %34)
%36 = add nsw i32 39, %35
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = mul i64 1, %38
%40 = trunc i64 %39 to i32
%41 = call i64 @malloc(i32 %40)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %4
%43 = load i8*, i8** %4
%44 = load i8*, i8** %3
%45 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = load i8*, i8** %4
%47 = call i32* @popen(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %47, i32** %6
%48 = load i32*, i32** %6
%49 = call signext i8 @fgetc(i32* %48)
store i8 %49, i8* %9
store i32 0, i32* %10
br label %50
50: ; preds = %69, %33
%51 = load i8, i8* %9
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 10
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i8, i8* %9
%56 = sext i8 %55 to i32
%57 = icmp ne i32 %56, 0
br label %58
58: ; preds = %54, %50
%59 = phi i1 [ false, %50 ], [ %57, %54 ]
br i1 %59, label %60, label %72
60: ; preds = %58
%61 = load i8, i8* %9
%62 = load i32, i32* %10
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %63
store i8 %61, i8* %64
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
%67 = load i32*, i32** %6
%68 = call signext i8 @fgetc(i32* %67)
store i8 %68, i8* %9
br label %69
69: ; preds = %60
%70 = load i32, i32* %10
%71 = add nsw i32 %70, 1
store i32 %71, i32* %10
br label %50
72: ; preds = %58
%73 = load i32, i32* %10
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %74
store i8 0, i8* %75
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = mul i64 1, %78
%80 = trunc i64 %79 to i32
%81 = call i64 @malloc(i32 %80)
%82 = inttoptr i64 %81 to i8*
store i8* %82, i8** %7
%83 = load i8*, i8** %7
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%85 = call i32 @strcpy(i8* %83, i8* %84)
%86 = load i8*, i8** %7
store i8* %86, i8** %2
br label %87
87: ; preds = %72, %31
%88 = load i8*, i8** %2
ret i8* %88
}

LLVM IR (-O2):
@.str = [33 x i8] c"whatis %s >/dev/null 2>/dev/null\00"
@.str.1 = [42 x i8] c"whatis %s |head -1 |sed -r -e 's/.* - //'\00"
@.str.2 = [2 x i8] c"r\00"
define i8* @whatis_get(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 31
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = tail call i32 @system(i8* %7)
%10 = tail call i32 @WEXITSTATUS(i32 %9)
%11 = tail call i32 @free(i8* %7)
%12 = icmp eq i32 %10, 0
br i1 %12, label %13, label %36
13: ; preds = %1
%14 = tail call i32 @strlen(i8* %0)
%15 = add nsw i32 %14, 40
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%19 = tail call i32* @popen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call signext i8 @fgetc(i32* %19)
br label %21
21: ; preds = %25, %13
%22 = phi i64 [ %28, %25 ], [ 0, %13 ]
%23 = phi i32 [ %29, %25 ], [ 1, %13 ]
%24 = phi i8 [ %27, %25 ], [ %20, %13 ]
switch i8 %24, label %25 [
i8 10, label %30
i8 0, label %30
]
25: ; preds = %21
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %22
store i8 %24, i8* %26
%27 = tail call signext i8 @fgetc(i32* %19)
%28 = add nuw i64 %22, 1
%29 = add nuw i32 %23, 1
br label %21
30: ; preds = %21, %21
%31 = and i64 %22, 4294967295
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %31
store i8 0, i8* %32
%33 = tail call i64 @malloc(i32 %23)
%34 = inttoptr i64 %33 to i8*
%35 = call i32 @strcpy(i8* %34, i8* %3)
br label %36
36: ; preds = %1, %30
%37 = phi i8* [ %34, %30 ], [ null, %1 ]
ret i8* %37
}