#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*/ startup;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int write(int, char *, int);
int main() {
  char startup[] = {
      0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x8,
  };
  int fd;
  int err;
  int rc = 1;
  fd = open("/dev/tpm0", O_RDWR);
  if (fd < 0) {
    printf("%s\n", "Unable to open the device.");
    goto out_noclose;
  }
  err = write(fd, startup, sizeof(startup));
  if (err != sizeof(startup)) {
    printf("%s%d\n", "Error occurred while sending command: ", errno);
    goto out;
  }
  rc = 0;
  printf("%s\n", "Physical presence asserted.");
out:
  close(fd);
out_noclose:
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xea8(%rip),%eax
mov    %eax,-0x8(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a6 <main+0x66>
lea    0xe83(%rip),%rdi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120f <main+0xcf>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    $0xc,%rax
je     11eb <main+0xab>
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
lea    0xe5d(%rip),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1207 <main+0xc7>
movl   $0x0,-0x1c(%rbp)
lea    0xe1d(%rip),%rdi
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movabs $0x400c000000c100,%rax
mov    %rax,0x8(%rsp)
movl   $0x8000a00,0x10(%rsp)
08
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11a7 <main+0x67>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1030 <write@plt>
cmp    $0xc,%eax
jne    11c3 <main+0x83>
lea    0xe81(%rip),%rdi
lea    0xec6(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e6 <main+0xa6>
lea    0xe68(%rip),%rdi
lea    0xe65(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
jmp    11ed <main+0xad>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
lea    0xe62(%rip),%rdi
lea    0xe61(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.startup = [12 x i8] c"\00\C1\00\00\00\0C@\00\00\0A\00\08"
@.str = [10 x i8] c"/dev/tpm0\00"
@O_RDWR = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [27 x i8] c"Unable to open the device.\00"
@.str.3 = [6 x i8] c"%s%d\0A\00"
@.str.4 = [39 x i8] c"Error occurred while sending command: \00"
@errno = global i32 0
@.str.5 = [28 x i8] c"Physical presence asserted.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [12 x i8]* %2 to i8*
store i32 1, i32* %5
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %28
13: ; preds = %0
%14 = load i32, i32* %3
%15 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%16 = call i32 @write(i32 %14, i8* %15, i32 12)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = icmp ne i64 %18, 12
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* @errno
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %21)
br label %25
23: ; preds = %13
store i32 0, i32* %5
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* %3
%27 = call i32 @close(i32 %26)
br label %28
28: ; preds = %25, %11
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
@__const.main.startup = [12 x i8] c"\00\C1\00\00\00\0C@\00\00\0A\00\08"
@.str = [10 x i8] c"/dev/tpm0\00"
@O_RDWR = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [27 x i8] c"Unable to open the device.\00"
@.str.3 = [6 x i8] c"%s%d\0A\00"
@.str.4 = [39 x i8] c"Error occurred while sending command: \00"
@errno = global i32 0
@.str.5 = [28 x i8] c"Physical presence asserted.\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %19
8: ; preds = %0
%9 = call i32 @write(i32 %4, i8* %2, i32 12)
%10 = icmp eq i32 %9, 12
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @errno
%13 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %12)
br label %16
14: ; preds = %8
%15 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = phi i32 [ 1, %11 ], [ 0, %14 ]
%18 = tail call i32 @close(i32 %4)
br label %19
19: ; preds = %16, %6
%20 = phi i32 [ 1, %6 ], [ %17, %16 ]
ret i32 %20
}