#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *str(int);
int sysclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *sysr(char const *);
int sysx(const char *cmd) {
  FILE *f = sysr(cmd);
  int le = 1000;
  char *buf = str(le);
  while (fgets(buf, le, f) != NULL) {
  }
  free(buf);
  if (f != NULL) {
    int ret = sysclose(f);
    return ret;
  } else
    return 1;
}


x86 assembly (clang, -O0):
<sysx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <sysr@plt>
mov    %rax,-0x18(%rbp)
movl   $0x3e8,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <str@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     119b <sysx+0x4b>
jmp    117c <sysx+0x2c>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
je     11c6 <sysx+0x76>
mov    -0x18(%rbp),%rdi
call   1040 <sysclose@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11cd <sysx+0x7d>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysx>:
push   %r14
push   %rbx
push   %rax
call   1070 <sysr@plt>
mov    %rax,%r14
mov    $0x3e8,%edi
call   1060 <str@plt>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1170 <sysx+0x20>
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     11a1 <sysx+0x51>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <sysclose@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @sysx(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32* @sysr(i8* %8)
store i32* %9, i32** %4
store i32 1000, i32* %5
%10 = load i32, i32* %5
%11 = call i8* @str(i32 %10)
store i8* %11, i8** %6
br label %12
12: ; preds = %18, %1
%13 = load i8*, i8** %6
%14 = load i32, i32* %5
%15 = load i32*, i32** %4
%16 = call i32* @fgets(i8* %13, i32 %14, i32* %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %12
br label %12
19: ; preds = %12
%20 = load i8*, i8** %6
%21 = call i32 @free(i8* %20)
%22 = load i32*, i32** %4
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i32*, i32** %4
%26 = call i32 @sysclose(i32* %25)
store i32 %26, i32* %7
%27 = load i32, i32* %7
store i32 %27, i32* %2
br label %29
28: ; preds = %19
store i32 1, i32* %2
br label %29
29: ; preds = %28, %24
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @sysx(i8* %0) {
%2 = tail call i32* @sysr(i8* %0)
%3 = tail call i8* @str(i32 1000)
br label %4
4: ; preds = %4, %1
%5 = tail call i32* @fgets(i8* %3, i32 1000, i32* %2)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %4
7: ; preds = %4
%8 = tail call i32 @free(i8* %3)
%9 = icmp eq i32* %2, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @sysclose(i32* %2)
br label %12
12: ; preds = %7, %10
%13 = phi i32 [ %11, %10 ], [ 1, %7 ]
ret i32 %13
}