#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 */
scalar_t__ g_read_file(char *, char *, int);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char const *argv[]) {
  char *buffer = malloc(sizeof(char));
  if (g_read_file("/sys/class/gpio/gpio37/value", buffer, 1)) {
    printf("Error en lectura\n");
    return 1;
  }
  printf("%c\n", *buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea1(%rip),%rdi
mov    $0x1,%edx
call   1040 <g_read_file@plt>
cmp    $0x0,%rax
je     118d <main+0x5d>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a9 <main+0x79>
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebp
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xea4(%rip),%rdi
mov    %rax,%rsi
mov    $0x1,%edx
call   1050 <g_read_file@plt>
test   %rax,%rax
je     117c <main+0x3c>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
jmp    118f <main+0x4f>
movsbl (%rbx),%esi
lea    0xe97(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"/sys/class/gpio/gpio37/value\00"
@.str.1 = [18 x i8] c"Error en lectura\0A\00"
@.str.2 = [4 x i8] c"%c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i8* @malloc(i32 1)
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = call i64 @g_read_file(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %8, i32 1)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %18
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %16)
store i32 0, i32* %3
br label %18
18: ; preds = %13, %11
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [29 x i8] c"/sys/class/gpio/gpio37/value\00"
@.str.2 = [4 x i8] c"%c\0A\00"
@str = [17 x i8] c"Error en lectura\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%4 = tail call i64 @g_read_file(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %3, i32 1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %12
8: ; preds = %2
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ 1, %6 ], [ 0, %8 ]
ret i32 %13
}