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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage: %s string\n", argv[0]);
    return 0;
  }
  char s[256];
  int fd;
  if ((fd = open("/proc/cfginfo", O_RDONLY)) < 0) {
    printf("cannot open file /proc/shm_dir/shm_info, error:[%d]\n", errno);
    return 0;
  }
  read(fd, s, 256);
  printf("%lx\n", *(unsigned long *)s);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1184 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1209 <main+0xc9>
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x114(%rbp)
cmp    $0x0,%eax
jge    11cb <main+0x8b>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1209 <main+0xc9>
mov    -0x114(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    -0x110(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x114(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
cmp    $0x2,%edi
jne    1192 <main+0x52>
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11a5 <main+0x65>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1050 <read@plt>
mov    (%rsp),%rsi
lea    0xed3(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11bc <main+0x7c>
mov    (%rsi),%rsi
lea    0xe64(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11bc <main+0x7c>
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s string\0A\00"
@.str.1 = [14 x i8] c"/proc/cfginfo\00"
@O_RDONLY = global i32 0
@.str.2 = [53 x i8] c"cannot open file /proc/shm_dir/shm_info, error:[%d]\0A\00"
@errno = global i32 0
@.str.3 = [5 x i8] c"%lx\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 0, i32* %3
br label %32
15: ; preds = %2
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i32 %17, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @errno
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %20)
store i32 0, i32* %3
br label %32
22: ; preds = %15
%23 = load i32, i32* %7
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%25 = call i32 @read(i32 %23, i8* %24, i32 256)
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%27 = bitcast i8* %26 to i64*
%28 = load i64, i64* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %28)
%30 = load i32, i32* %7
%31 = call i32 @close(i32 %30)
store i32 0, i32* %3
br label %32
32: ; preds = %22, %19, %10
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s string\0A\00"
@.str.1 = [14 x i8] c"/proc/cfginfo\00"
@O_RDONLY = global i32 0
@.str.2 = [53 x i8] c"cannot open file /proc/shm_dir/shm_info, error:[%d]\0A\00"
@errno = global i32 0
@.str.3 = [5 x i8] c"%lx\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %23
8: ; preds = %2
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* @errno
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %22
16: ; preds = %8
%17 = call i32 @read(i32 %11, i8* %9, i32 256)
%18 = bitcast [256 x i8]* %3 to i64*
%19 = load i64, i64* %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %19)
%21 = tail call i32 @close(i32 %11)
br label %22
22: ; preds = %16, %13
br label %23
23: ; preds = %22, %5
ret i32 0
}