#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main() {
  int ret;
  int fd;
  char *tmp;
  int i;
  fd = open("/dev/bmp180", O_RDWR);
  if (fd < 0) {
    printf("Unable to open device\n");
    exit(1);
  }
  printf("Succeed to open device\n");
  ret = read(fd, tmp, 2);
  if (ret <= 0)
    printf("Fail to read data\n");
  printf("Succeed to read data is %s\n", tmp);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1199 <main+0x49>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     11d3 <main+0x83>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11bd <main+0x5d>
mov    %eax,%ebx
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    $0x2,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     11a4 <main+0x44>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/bmp180\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Unable to open device\0A\00"
@.str.2 = [24 x i8] c"Succeed to open device\0A\00"
@.str.3 = [19 x i8] c"Fail to read data\0A\00"
@.str.4 = [28 x i8] c"Succeed to read data is %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDWR
%7 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* %3
%16 = load i8*, i8** %4
%17 = call i32 @read(i32 %15, i8* %16, i32 2)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %13
%23 = load i8*, i8** %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/bmp180\00"
@O_RDWR = global i32 0
@.str.4 = [28 x i8] c"Succeed to read data is %s\0A\00"
@str = [23 x i8] c"Succeed to open device\00"
@str.5 = [18 x i8] c"Fail to read data\00"
@str.6 = [22 x i8] c"Unable to open device\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @read(i32 %2, i8* undef, i32 2)
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* undef)
%15 = tail call i32 @close(i32 %2)
ret i32 0
}