#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*/ wtmp;
struct utmp {
  int /*<<< orphan*/ ut_time;
  int /*<<< orphan*/ ut_host;
  int /*<<< orphan*/ ut_name;
  int /*<<< orphan*/ ut_line;
};

/* Variables and functions */
int O_APPEND;
int O_WRONLY;
int /*<<< orphan*/ _PATH_WTMP;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int open(int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
markdown() {
  struct utmp wtmp;
  register int f = open(_PATH_WTMP, O_WRONLY | O_APPEND);
  if (f >= 0) {
    bzero((char *)&wtmp, sizeof(wtmp));
    strncpy(wtmp.ut_line, "~", sizeof(wtmp.ut_line));
    strncpy(wtmp.ut_name, "shutdown", sizeof(wtmp.ut_name));
    strncpy(wtmp.ut_host, "", sizeof(wtmp.ut_host));
    (void)time(&wtmp.ut_time);
    write(f, (char *)&wtmp, sizeof(wtmp));
    close(f);
  }
}


x86 assembly (clang, -O0):
<markdown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    0x2e47(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1201 <markdown+0xa1>
lea    -0x18(%rbp),%rdi
mov    $0x10,%esi
call   1080 <bzero@plt>
mov    -0xc(%rbp),%edi
lea    0xe53(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%edi
lea    0xe41(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%edi
lea    0xe35(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
lea    -0x18(%rbp),%rdi
call   1060 <time@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<markdown>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rax
mov    0x2e4a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     11fc <markdown+0x9c>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   1080 <bzero@plt>
mov    0x14(%rsp),%edi
lea    0xe56(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    0x10(%rsp),%edi
lea    0xe43(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    0xc(%rsp),%edi
lea    0xe36(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
call   1060 <time@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.utmp = type { i32, i32, i32, i32 }
@_PATH_WTMP = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str = [2 x i8] c"~\00"
@.str.1 = [9 x i8] c"shutdown\00"
@.str.2 = [1 x i8] zeroinitializer
define i32 @markdown() {
%1 = alloca i32
%2 = alloca %struct.utmp
%3 = alloca i32
%4 = load i32, i32* @_PATH_WTMP
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_APPEND
%7 = or i32 %5, %6
%8 = call i32 @open(i32 %4, i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %0
%12 = bitcast %struct.utmp* %2 to i8*
%13 = call i32 @bzero(i8* %12, i32 16)
%14 = getelementptr inbounds %struct.utmp, %struct.utmp* %2, i32 0, i32 3
%15 = load i32, i32* %14
%16 = call i32 @strncpy(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 4)
%17 = getelementptr inbounds %struct.utmp, %struct.utmp* %2, i32 0, i32 2
%18 = load i32, i32* %17
%19 = call i32 @strncpy(i32 %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 4)
%20 = getelementptr inbounds %struct.utmp, %struct.utmp* %2, i32 0, i32 1
%21 = load i32, i32* %20
%22 = call i32 @strncpy(i32 %21, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 4)
%23 = getelementptr inbounds %struct.utmp, %struct.utmp* %2, i32 0, i32 0
%24 = call i32 @time(i32* %23)
%25 = load i32, i32* %3
%26 = bitcast %struct.utmp* %2 to i8*
%27 = call i32 @write(i32 %25, i8* %26, i32 16)
%28 = load i32, i32* %3
%29 = call i32 @close(i32 %28)
br label %30
30: ; preds = %11, %0
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
%struct.utmp = type { i32, i32, i32, i32 }
@_PATH_WTMP = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str = [2 x i8] c"~\00"
@.str.1 = [9 x i8] c"shutdown\00"
@.str.2 = [1 x i8] zeroinitializer
define i32 @markdown() {
%1 = alloca %struct.utmp
%2 = bitcast %struct.utmp* %1 to i8*
%3 = load i32, i32* @_PATH_WTMP
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_APPEND
%6 = or i32 %5, %4
%7 = tail call i32 @open(i32 %3, i32 %6)
%8 = icmp sgt i32 %7, -1
br i1 %8, label %9, label %24
9: ; preds = %0
%10 = call i32 @bzero(i8* %2, i32 16)
%11 = getelementptr inbounds %struct.utmp, %struct.utmp* %1, i64 0, i32 3
%12 = load i32, i32* %11
%13 = tail call i32 @strncpy(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 4)
%14 = getelementptr inbounds %struct.utmp, %struct.utmp* %1, i64 0, i32 2
%15 = load i32, i32* %14
%16 = tail call i32 @strncpy(i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 4)
%17 = getelementptr inbounds %struct.utmp, %struct.utmp* %1, i64 0, i32 1
%18 = load i32, i32* %17
%19 = tail call i32 @strncpy(i32 %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 4)
%20 = getelementptr inbounds %struct.utmp, %struct.utmp* %1, i64 0, i32 0
%21 = call i32 @time(i32* %20)
%22 = call i32 @write(i32 %7, i8* %2, i32 16)
%23 = call i32 @close(i32 %7)
br label %24
24: ; preds = %9, %0
ret i32 undef
}