#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*/ uname;
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ date;
typedef int /*<<< orphan*/ cpuinfo;
typedef int /*<<< orphan*/ cmdline;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ proc_read(char *, char *, int);
char *strchr(char *, char);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void log_header(void) {
  FILE *out;
  char cmdline[1024];
  char uname[128];
  char cpuinfo[128];
  char *cpu;
  char date[32];
  time_t now_t = time(NULL);
  struct tm now = *localtime(&now_t);
  strftime(date, sizeof(date), "%x %X", &now);
  out = fopen("/data/bootchart"
              "/header",
              "w");
  if (out == NULL)
    return;
  proc_read("/proc/cmdline", cmdline, sizeof(cmdline));
  proc_read("/proc/version", uname, sizeof(uname));
  proc_read("/proc/cpuinfo", cpuinfo, sizeof(cpuinfo));
  cpu = strchr(cpuinfo, ':');
  if (cpu) {
    char *p = strchr(cpu, '\n');
    cpu += 2;
    if (p)
      *p = 0;
  }
  fprintf(out, "version = %s\n", "0.8");
  fprintf(out, "title = Boot chart for Android ( %s )\n", date);
  fprintf(out, "system.uname = %s\n", uname);
  fprintf(out, "system.release = 0.0\n");
  fprintf(out, "system.cpu = %s\n", cpu);
  fprintf(out, "system.kernel.options = %s\n", cmdline);
  fclose(out);
}


x86 assembly (clang, -O0):
<log_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x550,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0x544(%rbp)
lea    -0x544(%rbp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%eax
mov    %eax,-0x548(%rbp)
lea    -0x540(%rbp),%rdi
mov    $0x20,%esi
lea    0xe3f(%rip),%rdx
lea    -0x548(%rbp),%rcx
call   1090 <strftime@plt>
lea    0xe32(%rip),%rdi
lea    0xe42(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11f4 <log_header+0x74>
jmp    1341 <log_header+0x1c1>
lea    -0x410(%rbp),%rsi
lea    0xe1d(%rip),%rdi
mov    $0x400,%edx
call   1060 <proc_read@plt>
lea    -0x490(%rbp),%rsi
lea    0xe13(%rip),%rdi
mov    $0x80,%edx
call   1060 <proc_read@plt>
lea    -0x510(%rbp),%rsi
lea    0xe09(%rip),%rdi
mov    $0x80,%edx
call   1060 <proc_read@plt>
lea    -0x510(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x518(%rbp)
cmpq   $0x0,-0x518(%rbp)
je     12a9 <log_header+0x129>
mov    -0x518(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x550(%rbp)
mov    -0x518(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x518(%rbp)
cmpq   $0x0,-0x550(%rbp)
je     12a4 <log_header+0x124>
mov    -0x550(%rbp),%rax
movb   $0x0,(%rax)
jmp    12a9 <log_header+0x129>
mov    -0x8(%rbp),%rdi
lea    0xd95(%rip),%rsi
lea    0xd9c(%rip),%rdx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x540(%rbp),%rdx
lea    0xd87(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x490(%rbp),%rdx
lea    0xd95(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xd96(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x518(%rbp),%rdx
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x550,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_header>:
push   %r14
push   %rbx
sub    $0x538,%rsp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xe44(%rip),%rdx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rcx
mov    $0x20,%esi
call   1090 <strftime@plt>
lea    0xe2f(%rip),%rdi
lea    0xe3f(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12ff <log_header+0x16f>
mov    %rax,%rbx
lea    0xe29(%rip),%rdi
lea    0x130(%rsp),%rsi
mov    $0x400,%edx
call   1060 <proc_read@plt>
lea    0xe1e(%rip),%rdi
lea    0x30(%rsp),%rsi
mov    $0x80,%edx
call   1060 <proc_read@plt>
lea    0xe16(%rip),%rdi
lea    0xb0(%rsp),%r14
mov    %r14,%rsi
mov    $0x80,%edx
call   1060 <proc_read@plt>
mov    %r14,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     126a <log_header+0xda>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
add    $0x2,%r14
test   %rax,%rax
je     126d <log_header+0xdd>
movb   $0x0,(%rax)
jmp    126d <log_header+0xdd>
xor    %r14d,%r14d
lea    0xdd5(%rip),%rsi
lea    0xddc(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdcf(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xde0(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xddd(%rip),%rdi
mov    $0x15,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10b0 <fwrite@plt>
lea    0xdda(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xdd7(%rip),%rsi
lea    0x130(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x538,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [6 x i8] c"%x %X\00"
@.str.1 = [23 x i8] c"/data/bootchart/header\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [14 x i8] c"/proc/cmdline\00"
@.str.4 = [14 x i8] c"/proc/version\00"
@.str.5 = [14 x i8] c"/proc/cpuinfo\00"
@.str.6 = [14 x i8] c"version = %s\0A\00"
@.str.7 = [4 x i8] c"0.8\00"
@.str.8 = [39 x i8] c"title = Boot chart for Android ( %s )\0A\00"
@.str.9 = [19 x i8] c"system.uname = %s\0A\00"
@.str.10 = [22 x i8] c"system.release = 0.0\0A\00"
@.str.11 = [17 x i8] c"system.cpu = %s\0A\00"
@.str.12 = [28 x i8] c"system.kernel.options = %s\0A\00"
define void @log_header() {
%1 = alloca i32*
%2 = alloca [1024 x i8]
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca i8*
%6 = alloca [32 x i8]
%7 = alloca i32
%8 = alloca %struct.tm
%9 = alloca i8*
%10 = call i32 @time(i32* null)
store i32 %10, i32* %7
%11 = call %struct.tm* @localtime(i32* %7)
%12 = bitcast %struct.tm* %8 to i8*
%13 = bitcast %struct.tm* %11 to i8*
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%15 = call i32 @strftime(i8* %14, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %8)
%16 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %16, i32** %1
%17 = load i32*, i32** %1
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %0
br label %60
20: ; preds = %0
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%22 = call i32 @proc_read(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %21, i32 1024)
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%24 = call i32 @proc_read(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %23, i32 128)
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%26 = call i32 @proc_read(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %25, i32 128)
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%28 = call i8* @strchr(i8* %27, i8 signext 58)
store i8* %28, i8** %5
%29 = load i8*, i8** %5
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %41
31: ; preds = %20
%32 = load i8*, i8** %5
%33 = call i8* @strchr(i8* %32, i8 signext 10)
store i8* %33, i8** %9
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 2
store i8* %35, i8** %5
%36 = load i8*, i8** %9
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = load i8*, i8** %9
store i8 0, i8* %39
br label %40
40: ; preds = %38, %31
br label %41
41: ; preds = %40, %20
%42 = load i32*, i32** %1
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%44 = load i32*, i32** %1
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i8* %45)
%47 = load i32*, i32** %1
%48 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* %48)
%50 = load i32*, i32** %1
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
%52 = load i32*, i32** %1
%53 = load i8*, i8** %5
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i8* %53)
%55 = load i32*, i32** %1
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i8* %56)
%58 = load i32*, i32** %1
%59 = call i32 @fclose(i32* %58)
br label %60
60: ; preds = %41, %19
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [6 x i8] c"%x %X\00"
@.str.1 = [23 x i8] c"/data/bootchart/header\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [14 x i8] c"/proc/cmdline\00"
@.str.4 = [14 x i8] c"/proc/version\00"
@.str.5 = [14 x i8] c"/proc/cpuinfo\00"
@.str.6 = [14 x i8] c"version = %s\0A\00"
@.str.7 = [4 x i8] c"0.8\00"
@.str.8 = [39 x i8] c"title = Boot chart for Android ( %s )\0A\00"
@.str.9 = [19 x i8] c"system.uname = %s\0A\00"
@.str.10 = [22 x i8] c"system.release = 0.0\0A\00"
@.str.11 = [17 x i8] c"system.cpu = %s\0A\00"
@.str.12 = [28 x i8] c"system.kernel.options = %s\0A\00"
define void @log_header() {
%1 = alloca [1024 x i8]
%2 = alloca [128 x i8]
%3 = alloca [128 x i8]
%4 = alloca [32 x i8]
%5 = alloca i32
%6 = alloca %struct.tm
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%11 = bitcast i32* %5 to i8*
%12 = tail call i32 @time(i32* null)
store i32 %12, i32* %5
%13 = bitcast %struct.tm* %6 to i8*
%14 = call %struct.tm* @localtime(i32* %5)
%15 = getelementptr %struct.tm, %struct.tm* %14, i64 0, i32 0
%16 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%17 = load i32, i32* %15
store i32 %17, i32* %16
%18 = call i32 @strftime(i8* %10, i32 32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %struct.tm* %6)
%19 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %41, label %21
21: ; preds = %0
%22 = call i32 @proc_read(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %7, i32 1024)
%23 = call i32 @proc_read(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %8, i32 128)
%24 = call i32 @proc_read(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %9, i32 128)
%25 = call i8* @strchr(i8* %9, i8 signext 58)
%26 = icmp eq i8* %25, null
br i1 %26, label %32, label %27
27: ; preds = %21
%28 = call i8* @strchr(i8* %25, i8 signext 10)
%29 = getelementptr inbounds i8, i8* %25, i64 2
%30 = icmp eq i8* %28, null
br i1 %30, label %32, label %31
31: ; preds = %27
store i8 0, i8* %28
br label %32
32: ; preds = %27, %31, %21
%33 = phi i8* [ null, %21 ], [ %29, %31 ], [ %29, %27 ]
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i8* %10)
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* %8)
%37 = call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i64 21, i64 1, i32* %19)
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i8* %33)
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i8* %7)
%40 = call i32 @fclose(i32* %19)
br label %41
41: ; preds = %0, %32
ret void
}