#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*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
void config_uptime(int unit) {
  FILE *fs, *fd;
  char time[16];
  char *uptime_files[2] = {"/etc/ppp/pppoe1-dial-up-time",
                           "/etc/ppp/pppoe2-dial-up-time"};
  if ((fs = fopen("/proc/uptime", "r")) != NULL) {
    if ((fd = fopen(uptime_files[unit], "w")) != NULL) {
      fscanf(fs, "%s %*s", time);
      fprintf(fd, "%s", time);
      fclose(fd);
    }
    fclose(fs);
  }
}


x86 assembly (clang, -O0):
<config_uptime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2cbe(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2cbb(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xed2(%rip),%rdi
lea    0xed8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11df <config_uptime+0x9f>
movslq -0x4(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
lea    0xeb7(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d6 <config_uptime+0x96>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe97(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe8a(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_uptime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
lea    0xee9(%rip),%rdi
lea    0xeef(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ba <config_uptime+0x7a>
mov    %rax,%rbx
movslq %ebp,%rax
lea    0xee5(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
lea    0xecc(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b2 <config_uptime+0x72>
mov    %rax,%r14
lea    0xeba(%rip),%rsi
mov    %rsp,%rbp
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1050 <fscanf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"/etc/ppp/pppoe1-dial-up-time\00"
@.str.1 = [29 x i8] c"/etc/ppp/pppoe2-dial-up-time\00"
@__const.config_uptime.uptime_files = [2 x i8*] [i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [13 x i8] c"/proc/uptime\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [7 x i8] c"%s %*s\00"
@.str.6 = [3 x i8] c"%s\00"
define void @config_uptime(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [16 x i8]
%6 = alloca [2 x i8*]
store i32 %0, i32* %2
%7 = bitcast [2 x i8*]* %6 to i8*
%8 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %8, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %29
10: ; preds = %1
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %15, i32** %4
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %26
17: ; preds = %10
%18 = load i32*, i32** %3
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%20 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %4
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%23 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %4
%25 = call i32 @fclose(i32* %24)
br label %26
26: ; preds = %17, %10
%27 = load i32*, i32** %3
%28 = call i32 @fclose(i32* %27)
br label %29
29: ; preds = %26, %1
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"/etc/ppp/pppoe1-dial-up-time\00"
@.str.1 = [29 x i8] c"/etc/ppp/pppoe2-dial-up-time\00"
@reltable.config_uptime = [2 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([29 x i8]* @.str to i64), i64 ptrtoint ([2 x i32]* @reltable.config_uptime to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([29 x i8]* @.str.1 to i64), i64 ptrtoint ([2 x i32]* @reltable.config_uptime to i64)) to i32)]
@.str.2 = [13 x i8] c"/proc/uptime\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [7 x i8] c"%s %*s\00"
define void @config_uptime(i32 %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %18, label %6
6: ; preds = %1
%7 = sext i32 %0 to i64
%8 = shl i64 %7, 2
%9 = call i8* @llvm.load.relative.i64(i8* bitcast ([2 x i32]* @reltable.config_uptime to i8*), i64 %8)
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%14 = call i32 @fputs(i8* %3, i32* %10)
%15 = call i32 @fclose(i32* %10)
br label %16
16: ; preds = %12, %6
%17 = call i32 @fclose(i32* %4)
br label %18
18: ; preds = %16, %1
ret void
}