#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 scalar_t__ time_t;
struct timeval {
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ led_close();
scalar_t__ led_init();
int /*<<< orphan*/ stderr;
scalar_t__ update_time(scalar_t__);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  struct timeval tv;
  time_t last_sec = 0;
again:
  if (led_init() < 0) {
    led_close();
    return 0;
  }
  for (;;) {
    gettimeofday(&tv, 0);
    if (tv.tv_sec == last_sec) {
      usleep(20000);
      continue;
    }
    last_sec = tv.tv_sec;
    if (update_time(last_sec) < 0) {
      led_close();
      fprintf(stderr, "led_init: Re-open USB device\n");
      usleep(1000000);
      goto again;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1060 <led_init@plt>
cmp    $0x0,%rax
jge    119e <main+0x3e>
mov    $0x0,%al
call   1030 <led_close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
jmp    11a3 <main+0x43>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    11cb <main+0x6b>
mov    $0x4e20,%edi
call   1080 <usleep@plt>
jmp    11a3 <main+0x43>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <update_time@plt>
cmp    $0x0,%rax
jge    1211 <main+0xb1>
mov    $0x0,%al
call   1030 <led_close@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xf4240,%edi
call   1080 <usleep@plt>
jmp    117e <main+0x1e>
jmp    11a3 <main+0x43>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1060 <led_init@plt>
test   %rax,%rax
js     11fa <main+0x9a>
lea    0x8(%rsp),%r15
mov    0x2e57(%rip),%r12
lea    0xe70(%rip),%r14
xor    %r13d,%r13d
jmp    11aa <main+0x4a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x4e20,%edi
call   1080 <usleep@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%rbx
cmp    %r13,%rbx
je     11a0 <main+0x40>
mov    %rbx,%rdi
call   1050 <update_time@plt>
mov    %rbx,%r13
test   %rax,%rax
jns    11aa <main+0x4a>
xor    %eax,%eax
call   1030 <led_close@plt>
mov    (%r12),%edi
mov    %r14,%rsi
call   1070 <fprintf@plt>
mov    $0xf4240,%edi
call   1080 <usleep@plt>
xor    %eax,%eax
call   1060 <led_init@plt>
mov    %rbx,%r13
test   %rax,%rax
jns    11aa <main+0x4a>
xor    %eax,%eax
call   1030 <led_close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
@stderr = global i32 0
@.str = [30 x i8] c"led_init: Re-open USB device\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timeval
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
br label %8
8: ; preds = %28, %2
%9 = call i64 (...) @led_init()
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 (...) @led_close()
ret i32 0
13: ; preds = %8
br label %14
14: ; preds = %33, %20, %13
%15 = call i32 @gettimeofday(%struct.timeval* %6, i32 0)
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* %7
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @usleep(i32 20000)
br label %14
22: ; preds = %14
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%24 = load i64, i64* %23
store i64 %24, i64* %7
%25 = load i64, i64* %7
%26 = call i64 @update_time(i64 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %22
%29 = call i32 (...) @led_close()
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @usleep(i32 1000000)
br label %8
33: ; preds = %22
br label %14
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@stderr = global i32 0
@.str = [30 x i8] c"led_init: Re-open USB device\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i64 (...) @led_init()
%6 = icmp slt i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
br label %21
9: ; preds = %26, %2
%10 = call i32 (...) @led_close()
ret i32 0
11: ; preds = %21, %11
%12 = call i32 @usleep(i32 20000)
%13 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%14 = load i64, i64* %8
%15 = icmp eq i64 %14, %22
br i1 %15, label %11, label %16
16: ; preds = %11, %21
%17 = phi i64 [ %24, %21 ], [ %14, %11 ]
%18 = call i64 @update_time(i64 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %16, %26
br label %21
21: ; preds = %20, %7
%22 = phi i64 [ 0, %7 ], [ %17, %20 ]
%23 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%24 = load i64, i64* %8
%25 = icmp eq i64 %24, %22
br i1 %25, label %11, label %16
26: ; preds = %16
%27 = call i32 (...) @led_close()
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @usleep(i32 1000000)
%31 = call i64 (...) @led_init()
%32 = icmp slt i64 %31, 0
br i1 %32, label %9, label %20
}