#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 time_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int graphite_connect(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ time(int *);
int write(int, char *, scalar_t__);
int main() {
  char addr[] = "130.127.148.159\0";
  char basemessage[] = "system.graphite_test 1000";
  char sendmessage[100];
  char timemessage[30];
  time_t timer;
  int fd;
  int ret;
  char c;
  printf("starting\n");
  while (1) {
    fd = graphite_connect(addr);
    time(&timer);
    sprintf(sendmessage, "%s %u\n", basemessage, timer);
    printf("%s\n", sendmessage);
    ret = write(fd, sendmessage, strlen(sendmessage) + 1);
    printf("ret: %d\n", ret);
    close(fd);
    sleep(20);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe67(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe64(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe62(%rip),%al
mov    %al,-0x10(%rbp)
mov    0xe68(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe65(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe62(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe5f(%rip),%ax
mov    %ax,-0x28(%rbp)
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1070 <graphite_connect@plt>
mov    %eax,-0xd8(%rbp)
lea    -0xd4(%rbp),%rdi
call   1080 <time@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x40(%rbp),%rdx
mov    -0xd4(%rbp),%ecx
lea    0xe26(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0xb0(%rbp),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xd8(%rbp),%eax
mov    %eax,-0xf4(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    -0xb0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xf4(%rbp),%edi
mov    -0xf0(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0xe8(%rbp)
call   1030 <write@plt>
mov    %eax,-0xdc(%rbp)
mov    -0xdc(%rbp),%esi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xd8(%rbp),%edi
call   1060 <close@plt>
mov    $0x14,%edi
call   10a0 <sleep@plt>
jmp    11eb <main+0x6b>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
movaps 0xe58(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
movups 0xe71(%rip),%xmm0
movups %xmm0,0x3a(%rsp)
movaps 0xe5b(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%r15
lea    0xe58(%rip),%r12
lea    0x50(%rsp),%rbx
lea    0x30(%rsp),%r13
lea    0xe4e(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x10(%rsp),%rdi
call   1080 <graphite_connect@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1090 <time@plt>
mov    0xc(%rsp),%ecx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
mov    %rbp,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    $0x14,%edi
call   10b0 <sleep@plt>
jmp    1200 <main+0x70>

LLVM IR (-O0):
@__const.main.addr = [17 x i8] c"130.127.148.159\00\00"
@__const.main.basemessage = [26 x i8] c"system.graphite_test 1000\00"
@.str = [10 x i8] c"starting\0A\00"
@.str.1 = [7 x i8] c"%s %u\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [9 x i8] c"ret: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [17 x i8]
%3 = alloca [26 x i8]
%4 = alloca [100 x i8]
%5 = alloca [30 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %1
%10 = bitcast [17 x i8]* %2 to i8*
%11 = bitcast [26 x i8]* %3 to i8*
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %0, %13
%14 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%15 = call i32 @graphite_connect(i8* %14)
store i32 %15, i32* %7
%16 = call i32 @time(i32* %6)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%19 = load i32, i32* %6
%20 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %19)
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* %7
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%26 = call i64 @strlen(i8* %25)
%27 = add nsw i64 %26, 1
%28 = call i32 @write(i32 %23, i8* %24, i64 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %7
%32 = call i32 @close(i32 %31)
%33 = call i32 @sleep(i32 20)
br label %13
}

LLVM IR (-O2):
@__const.main.addr = [17 x i8] c"130.127.148.159\00\00"
@__const.main.basemessage = [26 x i8] c"system.graphite_test 1000\00"
@.str.1 = [7 x i8] c"%s %u\0A\00"
@.str.3 = [9 x i8] c"ret: %d\0A\00"
@str = [9 x i8] c"starting\00"
define i32 @main() {
%1 = alloca [17 x i8]
%2 = alloca [26 x i8]
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [26 x i8], [26 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %10, %0
%11 = call i32 @graphite_connect(i8* %5)
%12 = call i32 @time(i32* %4)
%13 = load i32, i32* %4
%14 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 %13)
%15 = call i32 @puts(i8* %7)
%16 = call i64 @strlen(i8* %7)
%17 = add nsw i64 %16, 1
%18 = call i32 @write(i32 %11, i8* %7, i64 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = call i32 @close(i32 %11)
%21 = call i32 @sleep(i32 20)
br label %10
}