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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ optind;
char *parse_command(int, char **, int /*<<< orphan*/);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *, ...);
int sleep(int);
scalar_t__ strlen(char *);
int strtol(int /*<<< orphan*/, int /*<<< orphan*/ *, int);
int system(char *);
int main(int argc, char **argv) {
  int opt;
  int delay = 2;
  while ((opt = getopt(argc, argv, "hd:")) != -1) {
    switch (opt) {
    case 'h':
      print_usage();
      exit(0);
    case 'd':
      delay = strtol(optarg, NULL, 10);
      if (delay == 0) {
        delay = 2;
      }
      break;
    }
  }
  char *commandstr = parse_command(argc, argv, optind);
  if (strlen(commandstr) == 0) {
    printf("Must provide command.\n");
    print_usage();
    exit(-1);
  }
  int result = system(commandstr);
  for (;;) {
    if (result == EXIT_SUCCESS) {
      exit(0);
    }
    int sleep_res = sleep(delay);
    if (sleep_res != 0) {
      printf("sleep interrupted: %d", sleep_res);
    }
    result = system(commandstr);
  }
  return EXIT_SUCCESS;
}


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   $0x2,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe45(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1234 <main+0xa4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x64,%eax
je     11ff <main+0x6f>
jmp    11e0 <main+0x50>
mov    -0x2c(%rbp),%eax
sub    $0x68,%eax
jne    122f <main+0x9f>
jmp    11f1 <main+0x61>
mov    $0x0,%al
call   10a0 <print_usage@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    122a <main+0x9a>
movl   $0x2,-0x18(%rbp)
jmp    122f <main+0x9f>
jmp    11ad <main+0x1d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2d9e(%rip),%rax
mov    (%rax),%edx
call   1070 <parse_command@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    127f <main+0xef>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   10a0 <print_usage@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d3b(%rip),%rcx
cmp    (%rcx),%eax
jne    12a4 <main+0x114>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
call   10b0 <sleep@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     12ca <main+0x13a>
mov    -0x28(%rbp),%esi
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x24(%rbp)
jmp    128b <main+0xfb>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x2,%r12d
lea    0xe53(%rip),%r15
mov    0x2e44(%rip),%r13
mov    $0x2,%r14d
jmp    11e0 <main+0x50>
mov    0x0(%r13),%edi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%r14d
test   %eax,%eax
cmove  %r12d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
cmp    $0x64,%eax
je     11bc <main+0x2c>
cmp    $0xffffffff,%eax
je     120a <main+0x7a>
cmp    $0x68,%eax
jne    11e0 <main+0x50>
xor    %eax,%eax
call   10a0 <print_usage@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <parse_command@plt>
cmpb   $0x0,(%rax)
jne    123f <main+0xaf>
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10a0 <print_usage@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <system@plt>
mov    0x2d7f(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    125d <main+0xcd>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xda0(%rip),%r15
jmp    127d <main+0xed>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <system@plt>
cmp    0x0(%rbp),%eax
je     1256 <main+0xc6>
mov    %r14d,%edi
call   10b0 <sleep@plt>
test   %eax,%eax
je     1270 <main+0xe0>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1270 <main+0xe0>

LLVM IR (-O0):
@.str = [4 x i8] c"hd:\00"
@optarg = global i32 0
@optind = global i32 0
@.str.1 = [23 x i8] c"Must provide command.\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [22 x i8] c"sleep interrupted: %d\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 i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2, i32* %7
br label %11
11: ; preds = %28, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %29
16: ; preds = %11
%17 = load i32, i32* %6
switch i32 %17, label %28 [
i32 104, label %18
i32 100, label %21
]
18: ; preds = %16
%19 = call i32 (...) @print_usage()
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %16
%22 = load i32, i32* @optarg
%23 = call i32 @strtol(i32 %22, i32* null, i32 10)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 2, i32* %7
br label %27
27: ; preds = %26, %21
br label %28
28: ; preds = %16, %27
br label %11
29: ; preds = %11
%30 = load i32, i32* %4
%31 = load i8**, i8*** %5
%32 = load i32, i32* @optind
%33 = call i8* @parse_command(i32 %30, i8** %31, i32 %32)
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = call i64 @strlen(i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %29
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 (...) @print_usage()
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %29
%42 = load i8*, i8** %8
%43 = call i32 @system(i8* %42)
store i32 %43, i32* %9
br label %44
44: ; preds = %58, %41
%45 = load i32, i32* %9
%46 = load i32, i32* @EXIT_SUCCESS
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %44
%51 = load i32, i32* %7
%52 = call i32 @sleep(i32 %51)
store i32 %52, i32* %10
%53 = load i32, i32* %10
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = load i32, i32* %10
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %55, %50
%59 = load i8*, i8** %8
%60 = call i32 @system(i8* %59)
store i32 %60, i32* %9
br label %44
}

LLVM IR (-O2):
@.str = [4 x i8] c"hd:\00"
@optarg = global i32 0
@optind = global i32 0
@EXIT_SUCCESS = global i32 0
@.str.2 = [22 x i8] c"sleep interrupted: %d\00"
@str = [22 x i8] c"Must provide command.\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %10, %2
%4 = phi i32 [ %14, %10 ], [ 2, %2 ]
br label %5
5: ; preds = %3, %5
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %5 [
i32 -1, label %15
i32 104, label %7
i32 100, label %10
]
7: ; preds = %5
%8 = tail call i32 (...) @print_usage()
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %5
%11 = load i32, i32* @optarg
%12 = tail call i32 @strtol(i32 %11, i32* null, i32 10)
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 2, i32 %12
br label %3
15: ; preds = %5
%16 = load i32, i32* @optind
%17 = tail call i8* @parse_command(i32 %0, i8** %1, i32 %16)
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 (...) @print_usage()
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %15
%25 = tail call i32 @system(i8* %17)
%26 = load i32, i32* @EXIT_SUCCESS
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %35, %24
%29 = tail call i32 @exit(i32 0)
unreachable
30: ; preds = %24, %35
%31 = tail call i32 @sleep(i32 %4)
%32 = icmp eq i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %35
35: ; preds = %33, %30
%36 = tail call i32 @system(i8* %17)
%37 = load i32, i32* @EXIT_SUCCESS
%38 = icmp eq i32 %36, %37
br i1 %38, label %28, label %30
}