#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*/ close(int);
int mstrain_capture_gyro_bias(int);
int mstrain_setup(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main() {
  int imu_fd = -1;
  int status = -1;
  char port_name[15];
  char *imu_port;
  int baud = 38400;
  strncpy(port_name, "/dev/ttyS0", 15);
  imu_port = port_name;
  printf("Trying IMU at %s with %d baud.\n", imu_port, baud);
  imu_fd = mstrain_setup(imu_port, baud);
  printf("imu_fd = %d\n", imu_fd);
  if (imu_fd < 0) {
    printf("No IMU, quitting...\n");
    return 0;
  }
  status = mstrain_capture_gyro_bias(imu_fd);
  close(imu_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0x9600,-0x2c(%rbp)
lea    -0x1b(%rbp),%rdi
lea    0xe81(%rip),%rsi
mov    $0xf,%edx
call   1030 <strncpy@plt>
lea    -0x1b(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1070 <mstrain_setup@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jge    11ea <main+0x9a>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1204 <main+0xb4>
mov    -0x8(%rbp),%edi
call   1060 <mstrain_capture_gyro_bias@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rsi
lea    0x1(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xf,%edx
call   1030 <strncpy@plt>
lea    0xe86(%rip),%rdi
mov    %rbx,%rsi
mov    $0x9600,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x9600,%esi
call   1080 <mstrain_setup@plt>
mov    %eax,%ebx
lea    0xe81(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
js     11c7 <main+0x67>
mov    %ebx,%edi
call   1070 <mstrain_capture_gyro_bias@plt>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    11d3 <main+0x73>
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/ttyS0\00"
@.str.1 = [32 x i8] c"Trying IMU at %s with %d baud.\0A\00"
@.str.2 = [13 x i8] c"imu_fd = %d\0A\00"
@.str.3 = [21 x i8] c"No IMU, quitting...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [15 x i8]
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 -1, i32* %3
store i32 38400, i32* %6
%7 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%8 = call i32 @strncpy(i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 15)
%9 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %11)
%13 = load i8*, i8** %5
%14 = load i32, i32* %6
%15 = call i32 @mstrain_setup(i8* %13, i32 %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %2
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %27
22: ; preds = %0
%23 = load i32, i32* %2
%24 = call i32 @mstrain_capture_gyro_bias(i32 %23)
store i32 %24, i32* %3
%25 = load i32, i32* %2
%26 = call i32 @close(i32 %25)
store i32 0, i32* %1
br label %27
27: ; preds = %22, %20
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/ttyS0\00"
@.str.1 = [32 x i8] c"Trying IMU at %s with %d baud.\0A\00"
@.str.2 = [13 x i8] c"imu_fd = %d\0A\00"
@str = [20 x i8] c"No IMU, quitting...\00"
define i32 @main() {
%1 = alloca [15 x i8]
%2 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%3 = call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 15)
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 38400)
%5 = call i32 @mstrain_setup(i8* %2, i32 38400)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %5, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %13
10: ; preds = %0
%11 = call i32 @mstrain_capture_gyro_bias(i32 %5)
%12 = call i32 @close(i32 %5)
br label %13
13: ; preds = %10, %8
ret i32 0
}