#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 O_RDWR;
int O_SYNC;
int /*<<< orphan*/ close(int);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int pwm_fclken_clock(int);
int pwm_iclken_clock(int);
int enable_i2c_clocls(void) {
  int res;
  int mem_fd = open("/dev/mem", O_RDWR | O_SYNC);
  if (mem_fd < 0) {
    printf("Can not open /dev/mem\n");
    return mem_fd;
  }
  res = pwm_fclken_clock(mem_fd);
  if (res) {
    printf("Error enabling FCLK for I2C2\n");
    return res;
  }
  res = pwm_iclken_clock(mem_fd);
  if (res) {
    printf("Error enabling ICLK for I2C2\n");
    return res;
  }
  close(mem_fd);
  return 0;
}


x86 assembly (clang, -O0):
<enable_i2c_clocls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    0x2e78(%rip),%rax
or     (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    119a <enable_i2c_clocls+0x4a>
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <enable_i2c_clocls+0xb1>
mov    -0xc(%rbp),%edi
call   1050 <pwm_fclken_clock@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11c6 <enable_i2c_clocls+0x76>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <enable_i2c_clocls+0xb1>
mov    -0xc(%rbp),%edi
call   1060 <pwm_iclken_clock@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11f2 <enable_i2c_clocls+0xa2>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1201 <enable_i2c_clocls+0xb1>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enable_i2c_clocls>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    0x2e7f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xedb(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     118d <enable_i2c_clocls+0x3d>
mov    %ebx,%edi
call   1050 <pwm_fclken_clock@plt>
test   %eax,%eax
je     119b <enable_i2c_clocls+0x4b>
mov    %eax,%ebp
lea    0xe92(%rip),%rdi
jmp    11af <enable_i2c_clocls+0x5f>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
jmp    11b6 <enable_i2c_clocls+0x66>
mov    %ebx,%edi
call   1060 <pwm_iclken_clock@plt>
test   %eax,%eax
je     11bf <enable_i2c_clocls+0x6f>
mov    %eax,%ebp
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebx,%edi
call   1040 <close@plt>
xor    %ebx,%ebx
jmp    11b6 <enable_i2c_clocls+0x66>

LLVM IR (-O0):
@.str = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.1 = [23 x i8] c"Can not open /dev/mem\0A\00"
@.str.2 = [30 x i8] c"Error enabling FCLK for I2C2\0A\00"
@.str.3 = [30 x i8] c"Error enabling ICLK for I2C2\0A\00"
define i32 @enable_i2c_clocls() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_SYNC
%6 = or i32 %4, %5
%7 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 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 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %3
store i32 %12, i32* %1
br label %32
13: ; preds = %0
%14 = load i32, i32* %3
%15 = call i32 @pwm_fclken_clock(i32 %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* %2
store i32 %20, i32* %1
br label %32
21: ; preds = %13
%22 = load i32, i32* %3
%23 = call i32 @pwm_iclken_clock(i32 %22)
store i32 %23, i32* %2
%24 = load i32, i32* %2
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* %2
store i32 %28, i32* %1
br label %32
29: ; preds = %21
%30 = load i32, i32* %3
%31 = call i32 @close(i32 %30)
store i32 0, i32* %1
br label %32
32: ; preds = %29, %26, %18, %10
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@.str = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@str = [29 x i8] c"Error enabling ICLK for I2C2\00"
@str.4 = [29 x i8] c"Error enabling FCLK for I2C2\00"
@str.5 = [22 x i8] c"Can not open /dev/mem\00"
define i32 @enable_i2c_clocls() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_SYNC
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.5, i64 0, i64 0))
br label %20
8: ; preds = %0
%9 = tail call i32 @pwm_fclken_clock(i32 %4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.4, i64 0, i64 0))
br label %20
13: ; preds = %8
%14 = tail call i32 @pwm_iclken_clock(i32 %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %20
18: ; preds = %13
%19 = tail call i32 @close(i32 %4)
br label %20
20: ; preds = %18, %16, %11, %6
%21 = phi i32 [ %4, %6 ], [ %9, %11 ], [ %14, %16 ], [ 0, %18 ]
ret i32 %21
}