#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
void help_cmd(int argc, char **argv) {
  char str[50];
  FILE *pfile;
  pfile = fopen("/usr/share/sesh/HELP", "r");
  if (pfile == NULL) {
    puts("Sorry, help is unavailable now.");
  } else {
    puts("This is help:");
    while (fgets(str, 50, pfile) != NULL)
      printf("%s", str);
    fclose(pfile);
  }
}


x86 assembly (clang, -O0):
<help_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1192 <help_cmd+0x42>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
jmp    11d8 <help_cmd+0x88>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    $0x32,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11cf <help_cmd+0x7f>
lea    -0x50(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
jmp    119e <help_cmd+0x4e>
mov    -0x58(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<help_cmd>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xea0(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d2 <help_cmd+0x82>
mov    %rax,%r15
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0x32,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11c0 <help_cmd+0x70>
lea    0xea9(%rip),%r14
mov    %rsp,%rbx
nop
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x32,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11a0 <help_cmd+0x50>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe3e(%rip),%rdi
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"/usr/share/sesh/HELP\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"Sorry, help is unavailable now.\00"
@.str.3 = [14 x i8] c"This is help:\00"
@.str.4 = [3 x i8] c"%s\00"
define void @help_cmd(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [50 x i8]
%6 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 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** %6
%8 = load i32*, i32** %6
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %25
12: ; preds = %2
%13 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %19, %12
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i32* @fgets(i8* %15, i32 50, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %20)
br label %14
22: ; preds = %14
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %22, %10
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"/usr/share/sesh/HELP\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [32 x i8] c"Sorry, help is unavailable now.\00"
@.str.3 = [14 x i8] c"This is help:\00"
@.str.4 = [3 x i8] c"%s\00"
define void @help_cmd(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 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 = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %19
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32* @fgets(i8* %4, i32 50, i32* %5)
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %9, %13
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%15 = call i32* @fgets(i8* %4, i32 50, i32* %5)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %13
17: ; preds = %13, %9
%18 = call i32 @fclose(i32* %5)
br label %19
19: ; preds = %17, %7
ret void
}