#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int getbaseaddr(int parport_num) {
  FILE *fufu;
  char buffer[128];
  int a;
  snprintf(buffer, 128, "/proc/sys/dev/parport/parport%d/base-addr",
           parport_num);
  fufu = fopen(buffer, "r");
  if (fufu == NULL)
    return 888;
  fscanf(fufu, "%d", &a);
  fclose(fufu);
  return a;
}


x86 assembly (clang, -O0):
<getbaseaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x80,%esi
lea    0xe9c(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1197 <getbaseaddr+0x57>
movl   $0x378,-0x4(%rbp)
jmp    11c0 <getbaseaddr+0x80>
mov    -0x10(%rbp),%rdi
lea    0xe88(%rip),%rsi
lea    -0x94(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x94(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbaseaddr>:
push   %rbx
sub    $0x90,%rsp
mov    %edi,%ecx
lea    0xeaf(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1040 <snprintf@plt>
lea    0xebe(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     119c <getbaseaddr+0x5c>
mov    %rax,%rbx
lea    0xea9(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
jmp    11a1 <getbaseaddr+0x61>
mov    $0x378,%eax
add    $0x90,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [42 x i8] c"/proc/sys/dev/parport/parport%d/base-addr\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @getbaseaddr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [128 x i8]
%6 = alloca i32
store i32 %0, i32* %3
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 @snprintf(i8* %7, i32 128, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 888, i32* %2
br label %21
15: ; preds = %1
%16 = load i32*, i32** %4
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%18 = load i32*, i32** %4
%19 = call i32 @fclose(i32* %18)
%20 = load i32, i32* %6
store i32 %20, i32* %2
br label %21
21: ; preds = %15, %14
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [42 x i8] c"/proc/sys/dev/parport/parport%d/base-addr\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @getbaseaddr(i32 %0) {
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = call i32 @snprintf(i8* %4, i32 128, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%11 = call i32 @fclose(i32* %7)
%12 = load i32, i32* %3
br label %13
13: ; preds = %1, %9
%14 = phi i32 [ %12, %9 ], [ 888, %1 ]
ret i32 %14
}