#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*/ close_timer(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int init_timer(int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_timer(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
FILE *reinit_timer(FILE *port, char *name, int config, int lanes_expected) {
  FILE *fd;
  char tmp[80];
  int lanes;
  printf("Wow, something's messed with your timer. Let's try again.\n");
  close_timer(port);
  printf("Please power cycle your timer.\n");
  printf("If you have a USB timer, just unplug it, wait a few seconds, and "
         "reconnect\n");
  printf("it to the SAME port.\n");
  printf("\nWhen you're done, press Enter and we'll try to get reconnected.\n");
retry:
  fgets(tmp, 80, stdin);
  printf("Opening port.\n");
  fd = open_timer(name, config);
  if (!fd) {
    printf("Eek! Unable to open timer port! Please power cycle it again.\n");
    printf(
        "Double-check that you plugged your USB timer into the same port!\n");
    printf("Press Enter to try again. (Ctrl-C to give up - you will lose all "
           "results.)\n");
    goto retry;
  }
  lanes = init_timer(fd);
  if (lanes != lanes_expected) {
    close_timer(fd);
    printf("Eek! Invalid number of lanes! (Expected %d, got %d from timer.\n",
           lanes_expected, lanes);
    printf("Please power cycle your timer again and check all sensor "
           "connections.\n");
    printf("Press Enter to try again. (Ctrl-C to give up - you will lose all "
           "results.)\n");
    goto retry;
  }
  return fd;
}


x86 assembly (clang, -O0):
<reinit_timer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <close_timer@plt>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1040 <fgets@plt>
lea    0xf29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <open_timer@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1227 <reinit_timer+0xd7>
lea    0xf0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b8 <reinit_timer+0x68>
mov    -0x20(%rbp),%rdi
call   1060 <init_timer@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     127d <reinit_timer+0x12d>
mov    -0x20(%rbp),%rdi
call   1050 <close_timer@plt>
mov    -0x18(%rbp),%esi
mov    -0x74(%rbp),%edx
lea    0xf85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xfb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b8 <reinit_timer+0x68>
mov    -0x20(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reinit_timer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%r15
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1060 <close_timer@plt>
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
lea    0xef9(%rip),%rdi
call   1030 <puts@plt>
lea    0xf38(%rip),%rdi
call   1030 <puts@plt>
lea    0xf41(%rip),%rdi
call   1030 <puts@plt>
lea    0x1048(%rip),%r13
jmp    11f0 <reinit_timer+0x90>
cs nopw 0x0(%rax,%rax,1)
lea    0xf71(%rip),%rdi
call   1030 <puts@plt>
lea    0xfa2(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x50,%esi
call   1050 <fgets@plt>
lea    0xf2d(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1080 <open_timer@plt>
test   %rax,%rax
je     11d0 <reinit_timer+0x70>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <init_timer@plt>
cmp    %ebx,%eax
je     1258 <reinit_timer+0xf8>
mov    %eax,%r12d
mov    %r15,%rdi
call   1060 <close_timer@plt>
lea    0xdbd(%rip),%rdi
mov    %ebx,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf70(%rip),%rdi
jmp    11e3 <reinit_timer+0x83>
mov    %r15,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"Wow, something's messed with your timer. Let's try again.\0A\00"
@.str.1 = [32 x i8] c"Please power cycle your timer.\0A\00"
@.str.2 = [76 x i8] c"If you have a USB timer, just unplug it, wait a few seconds, and reconnect\0A\00"
@.str.3 = [22 x i8] c"it to the SAME port.\0A\00"
@.str.4 = [66 x i8] c"\0AWhen you're done, press Enter and we'll try to get reconnected.\0A\00"
@stdin = global i32 0
@.str.5 = [15 x i8] c"Opening port.\0A\00"
@.str.6 = [62 x i8] c"Eek! Unable to open timer port! Please power cycle it again.\0A\00"
@.str.7 = [66 x i8] c"Double-check that you plugged your USB timer into the same port!\0A\00"
@.str.8 = [76 x i8] c"Press Enter to try again. (Ctrl-C to give up - you will lose all results.)\0A\00"
@.str.9 = [64 x i8] c"Eek! Invalid number of lanes! (Expected %d, got %d from timer.\0A\00"
@.str.10 = [71 x i8] c"Please power cycle your timer again and check all sensor connections.\0A\00"
define i32* @reinit_timer(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca [80 x i8]
%11 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%13 = load i32*, i32** %5
%14 = call i32 @close_timer(i32* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %39, %29, %4
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%21 = load i32, i32* @stdin
%22 = call i32 @fgets(i8* %20, i32 80, i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%24 = load i8*, i8** %6
%25 = load i32, i32* %7
%26 = call i32* @open_timer(i8* %24, i32 %25)
store i32* %26, i32** %9
%27 = load i32*, i32** %9
%28 = icmp ne i32* %27, null
br i1 %28, label %33, label %29
29: ; preds = %19
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.7, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.8, i64 0, i64 0))
br label %19
33: ; preds = %19
%34 = load i32*, i32** %9
%35 = call i32 @init_timer(i32* %34)
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = load i32, i32* %8
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %47
39: ; preds = %33
%40 = load i32*, i32** %9
%41 = call i32 @close_timer(i32* %40)
%42 = load i32, i32* %8
%43 = load i32, i32* %11
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.9, i64 0, i64 0), i32 %42, i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.10, i64 0, i64 0))
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.8, i64 0, i64 0))
br label %19
47: ; preds = %33
%48 = load i32*, i32** %9
ret i32* %48
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.9 = [64 x i8] c"Eek! Invalid number of lanes! (Expected %d, got %d from timer.\0A\00"
@str = [58 x i8] c"Wow, something's messed with your timer. Let's try again.\00"
@str.11 = [31 x i8] c"Please power cycle your timer.\00"
@str.12 = [75 x i8] c"If you have a USB timer, just unplug it, wait a few seconds, and reconnect\00"
@str.13 = [21 x i8] c"it to the SAME port.\00"
@str.14 = [65 x i8] c"\0AWhen you're done, press Enter and we'll try to get reconnected.\00"
@str.15 = [14 x i8] c"Opening port.\00"
@str.16 = [61 x i8] c"Eek! Unable to open timer port! Please power cycle it again.\00"
@str.17 = [65 x i8] c"Double-check that you plugged your USB timer into the same port!\00"
@str.19 = [70 x i8] c"Please power cycle your timer again and check all sensor connections.\00"
@str.20 = [75 x i8] c"Press Enter to try again. (Ctrl-C to give up - you will lose all results.)\00"
define i32* @reinit_timer(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [80 x i8]
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @close_timer(i32* %0)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.11, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str.12, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.13, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.14, i64 0, i64 0))
br label %13
13: ; preds = %21, %4
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %6, i32 80, i32 %14)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.15, i64 0, i64 0))
%17 = call i32* @open_timer(i8* %1, i32 %2)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %26
19: ; preds = %13
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.16, i64 0, i64 0))
br label %21
21: ; preds = %19, %29
%22 = phi i8* [ getelementptr inbounds ([65 x i8], [65 x i8]* @str.17, i64 0, i64 0), %19 ], [ getelementptr inbounds ([70 x i8], [70 x i8]* @str.19, i64 0, i64 0), %29 ]
%23 = phi i8* [ getelementptr inbounds ([75 x i8], [75 x i8]* @str.20, i64 0, i64 0), %19 ], [ getelementptr inbounds ([75 x i8], [75 x i8]* @str.20, i64 0, i64 0), %29 ]
%24 = call i32 @puts(i8* dereferenceable(1) %22)
%25 = call i32 @puts(i8* dereferenceable(1) %23)
br label %13
26: ; preds = %13
%27 = call i32 @init_timer(i32* %17)
%28 = icmp eq i32 %27, %3
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = call i32 @close_timer(i32* %17)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.9, i64 0, i64 0), i32 %3, i32 %27)
br label %21
32: ; preds = %26
ret i32* %17
}