#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 /*<<< orphan*/ fflush(int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ system(char *);
scalar_t__ tgetent(int /*<<< orphan*/ *, char *);
char *tgetstr(char *, int /*<<< orphan*/ *);
void main() {
  unsigned int counter = 0;
  char *clearstring;
  char *termtype = getenv("TERM");
  if (tgetent(NULL, termtype)) {
    clearstring = tgetstr("cl", NULL);
    printf("%s", clearstring);
  }
  printf("ReDial.\n");
  for (;;) {
    counter++;
    printf("Dialing[%7d]", counter);
    fflush(stdout);
    system("exec /usr/sbin/pppd -detach /dev/cua0 connect \"/usr/sbin/chat -v "
           "-f /home/egustafs/.chatrc2\"");
    printf(" -- connection lost.\n");
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <tgetent@plt>
cmp    $0x0,%rax
je     11cc <main+0x5c>
lea    0xe58(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <tgetstr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xe15(%rip),%rdi
call   1040 <system@plt>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    11da <main+0x6a>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xe70(%rip),%rdi
call   1030 <getenv@plt>
xor    %edi,%edi
mov    %rax,%rsi
call   1070 <tgetent@plt>
test   %rax,%rax
je     11c3 <main+0x43>
lea    0xe5a(%rip),%rdi
xor    %esi,%esi
call   1090 <tgetstr@plt>
lea    0xe4f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeab(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
lea    0xe30(%rip),%r14
mov    0x2dfe(%rip),%r13
lea    0xe2f(%rip),%r15
lea    0xe8d(%rip),%r12
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13),%edi
call   1080 <fflush@plt>
mov    %r15,%rdi
call   1050 <system@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
add    $0x1,%ebx
jmp    11f0 <main+0x70>

LLVM IR (-O0):
@.str = [5 x i8] c"TERM\00"
@.str.1 = [3 x i8] c"cl\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [9 x i8] c"ReDial.\0A\00"
@.str.4 = [13 x i8] c"Dialing[%7d]\00"
@stdout = global i32 0
@.str.5 = [93 x i8] c"exec /usr/sbin/pppd -detach /dev/cua0 connect \22/usr/sbin/chat -v -f /home/egustafs/.chatrc2\22\00"
@.str.6 = [22 x i8] c" -- connection lost.\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @tgetent(i32* null, i8* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i8* @tgetstr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null)
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %8, %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %14, %12
%15 = load i32, i32* %1
%16 = add i32 %15, 1
store i32 %16, i32* %1
%17 = load i32, i32* %1
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @stdout
%20 = call i32 @fflush(i32 %19)
%21 = call i32 @system(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%23 = call i32 @sleep(i32 1)
br label %14
}

LLVM IR (-O2):
@.str = [5 x i8] c"TERM\00"
@.str.1 = [3 x i8] c"cl\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.4 = [13 x i8] c"Dialing[%7d]\00"
@stdout = global i32 0
@.str.5 = [93 x i8] c"exec /usr/sbin/pppd -detach /dev/cua0 connect \22/usr/sbin/chat -v -f /home/egustafs/.chatrc2\22\00"
@str = [8 x i8] c"ReDial.\00"
@str.7 = [21 x i8] c" -- connection lost.\00"
define void @main() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @tgetent(i32* null, i8* %1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = tail call i8* @tgetstr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* null)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %7
7: ; preds = %4, %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %9, %7
%10 = phi i32 [ 0, %7 ], [ %11, %9 ]
%11 = add i32 %10, 1
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @stdout
%14 = tail call i32 @fflush(i32 %13)
%15 = tail call i32 @system(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.5, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0))
%17 = tail call i32 @sleep(i32 1)
br label %9
}