#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 FindMotors(int, int);
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *);
void main(void) {
  int file;
  char filename[40];
  int addr = 0x48 >> 1;
  sprintf(filename, "/dev/i2c-2");
  if ((file = open(filename, O_RDWR)) < 0) {
    printf("Failed to open the bus.");
    exit(1);
  }
  printf("%d Motors Found!\n", FindMotors(file, addr));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x24,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    11a5 <main+0x55>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1050 <FindMotors@plt>
mov    %eax,%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
movabs $0x6332692f7665642f,%rax
69 32 63
mov    %rax,(%rsp)
movl   $0x322d63,0x7(%rsp)
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1040 <open@plt>
test   %eax,%eax
js     118f <main+0x4f>
mov    %eax,%edi
mov    $0x24,%esi
call   1050 <FindMotors@plt>
lea    0xea1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
add    $0x28,%rsp
jmp    1030 <printf@plt>
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/i2c-2\00"
@O_RDWR = global i32 0
@.str.1 = [24 x i8] c"Failed to open the bus.\00"
@.str.2 = [18 x i8] c"%d Motors Found!\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca [40 x i8]
%3 = alloca i32
store i32 36, i32* %3
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %1
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i32, i32* %1
%15 = load i32, i32* %3
%16 = call i32 @FindMotors(i32 %14, i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %16)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/i2c-2\00"
@O_RDWR = global i32 0
@.str.1 = [24 x i8] c"Failed to open the bus.\00"
@.str.2 = [18 x i8] c"%d Motors Found!\0A\00"
define void @main() {
%1 = alloca [40 x i8]
%2 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = call i32 @open(i8* %2, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call i32 @FindMotors(i32 %4, i32 36)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %10)
ret void
}