#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  int done;
  FILE *ef;
  int status;
  status = 0;
  fprintf(stderr, "repeating command: %s\n", argv[1]);
  done = 0;
  system("echo yes >server_enable");
  while (!done) {
    system(argv[1]);
    sleep(5);
    ef = fopen("server_enable", "r");
    if (ef == NULL) {
      fprintf(stderr, "server no longer enabled.  exiting.\n");
      done = 1;
    };
  };
  if (status != 0)
    fprintf(stderr, "exit with status %d\n", status);
  return (status);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
lea    0xe8d(%rip),%rdi
call   1030 <system@plt>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a5 <main+0x65>
jmp    1201 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <system@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
lea    0xe5e(%rip),%rdi
lea    0xe65(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fc <main+0xbc>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    118f <main+0x4f>
cmpl   $0x0,-0x24(%rbp)
je     1225 <main+0xe5>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e8e(%rip),%r12
mov    (%r12),%edi
mov    0x8(%rsi),%rdx
lea    0xe9f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xea8(%rip),%rdi
call   1030 <system@plt>
lea    0xea6(%rip),%r14
lea    0xead(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%rbx),%rdi
call   1030 <system@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <fopen@plt>
test   %rax,%rax
jne    1190 <main+0x50>
mov    (%r12),%edi
lea    0xe73(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"repeating command: %s\0A\00"
@.str.1 = [24 x i8] c"echo yes >server_enable\00"
@.str.2 = [14 x i8] c"server_enable\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [37 x i8] c"server no longer enabled. exiting.\0A\00"
@.str.5 = [21 x i8] c"exit with status %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* @stderr
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 0, i32* %6
%14 = call i32 @system(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %31, %2
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @system(i8* %22)
%24 = call i32 @sleep(i32 5)
%25 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %25, i32** %7
%26 = load i32*, i32** %7
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %6
br label %31
31: ; preds = %28, %19
br label %15
32: ; preds = %15
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = load i32, i32* %8
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %35, %32
%40 = load i32, i32* %8
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"repeating command: %s\0A\00"
@.str.1 = [24 x i8] c"echo yes >server_enable\00"
@.str.2 = [14 x i8] c"server_enable\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [37 x i8] c"server no longer enabled. exiting.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @stderr
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @system(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %8, %2
%9 = load i8*, i8** %4
%10 = tail call i32 @system(i8* %9)
%11 = tail call i32 @sleep(i32 5)
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %8
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}