#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 fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
void getPhyLogSizes(const char *suffix, size_t *phy, size_t *log) {
  *phy = 512;
  *log = 512;
  if (suffix) {
    char s[1000];
    sprintf(s, "/sys/block/%s/queue/physical_block_size", suffix);
    int d, ret;
    FILE *fp = fopen(s, "rt");
    if (!fp) {
    } else {
      ret = fscanf(fp, "%d", &d);
      fclose(fp);
      if (ret == 1) {
        *phy = d;
      }
    }
    sprintf(s, "/sys/block/%s/queue/logical_block_size", suffix);
    fp = fopen(s, "rt");
    if (!fp) {
      *log = 512;
    } else {
      ret = fscanf(fp, "%d", &d);
      fclose(fp);
      if (ret == 1) {
        *log = d;
      }
    }
  }
}


x86 assembly (clang, -O0):
<getPhyLogSizes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x200,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x200,(%rax)
cmpq   $0x0,-0x8(%rbp)
je     12a8 <getPhyLogSizes+0x168>
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x400(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x410(%rbp)
cmpq   $0x0,-0x410(%rbp)
jne    11bc <getPhyLogSizes+0x7c>
jmp    1208 <getPhyLogSizes+0xc8>
mov    -0x410(%rbp),%rdi
lea    0xe61(%rip),%rsi
lea    -0x404(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x408(%rbp)
mov    -0x410(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x1,-0x408(%rbp)
jne    1203 <getPhyLogSizes+0xc3>
movslq -0x404(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1208 <getPhyLogSizes+0xc8>
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe14(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x400(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x410(%rbp)
cmpq   $0x0,-0x410(%rbp)
jne    1257 <getPhyLogSizes+0x117>
mov    -0x18(%rbp),%rax
movq   $0x200,(%rax)
jmp    12a3 <getPhyLogSizes+0x163>
mov    -0x410(%rbp),%rdi
lea    0xdc6(%rip),%rsi
lea    -0x404(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x408(%rbp)
mov    -0x410(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x1,-0x408(%rbp)
jne    129e <getPhyLogSizes+0x15e>
movslq -0x404(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    12a3 <getPhyLogSizes+0x163>
jmp    12a8 <getPhyLogSizes+0x168>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPhyLogSizes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
movq   $0x200,(%rsi)
movq   $0x200,(%rdx)
test   %rdi,%rdi
je     1228 <getPhyLogSizes+0xe8>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe8a(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rdx
call   1060 <sprintf@plt>
lea    0xe9b(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c8 <getPhyLogSizes+0x88>
mov    %rax,%rbx
lea    0xe87(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%ebp
jne    11c8 <getPhyLogSizes+0x88>
movslq 0xc(%rsp),%rax
mov    %rax,(%r15)
lea    0xe5f(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rdx
call   1060 <sprintf@plt>
lea    0xe42(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1220 <getPhyLogSizes+0xe0>
mov    %rax,%rbx
lea    0xe2e(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%ebp
jne    1228 <getPhyLogSizes+0xe8>
movslq 0xc(%rsp),%rax
jmp    1225 <getPhyLogSizes+0xe5>
mov    $0x200,%eax
mov    %rax,(%r14)
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"/sys/block/%s/queue/physical_block_size\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [39 x i8] c"/sys/block/%s/queue/logical_block_size\00"
define void @getPhyLogSizes(i8* %0, i64* %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca [1000 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i8* %0, i8** %4
store i64* %1, i64** %5
store i64* %2, i64** %6
%11 = load i64*, i64** %5
store i64 512, i64* %11
%12 = load i64*, i64** %6
store i64 512, i64* %12
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %59
15: ; preds = %3
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%17 = load i8*, i8** %4
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %10
%21 = load i32*, i32** %10
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %15
br label %36
24: ; preds = %15
%25 = load i32*, i32** %10
%26 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
store i32 %26, i32* %9
%27 = load i32*, i32** %10
%28 = call i32 @fclose(i32* %27)
%29 = load i32, i32* %9
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = load i64*, i64** %5
store i64 %33, i64* %34
br label %35
35: ; preds = %31, %24
br label %36
36: ; preds = %35, %23
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%38 = load i8*, i8** %4
%39 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %41, i32** %10
%42 = load i32*, i32** %10
%43 = icmp ne i32* %42, null
br i1 %43, label %46, label %44
44: ; preds = %36
%45 = load i64*, i64** %6
store i64 512, i64* %45
br label %58
46: ; preds = %36
%47 = load i32*, i32** %10
%48 = call i32 @fscanf(i32* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
store i32 %48, i32* %9
%49 = load i32*, i32** %10
%50 = call i32 @fclose(i32* %49)
%51 = load i32, i32* %9
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %57
53: ; preds = %46
%54 = load i32, i32* %8
%55 = sext i32 %54 to i64
%56 = load i64*, i64** %6
store i64 %55, i64* %56
br label %57
57: ; preds = %53, %46
br label %58
58: ; preds = %57, %44
br label %59
59: ; preds = %58, %3
ret void
}

LLVM IR (-O2):
@.str = [40 x i8] c"/sys/block/%s/queue/physical_block_size\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [39 x i8] c"/sys/block/%s/queue/logical_block_size\00"
define void @getPhyLogSizes(i8* %0, i64* nocapture writeonly %1, i64* nocapture writeonly %2) {
%4 = alloca [1000 x i8]
%5 = alloca i32
store i64 512, i64* %1
store i64 512, i64* %2
%6 = icmp eq i8* %0, null
br i1 %6, label %34, label %7
7: ; preds = %3
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%9 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = bitcast i32* %5 to i8*
%11 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %20, label %13
13: ; preds = %7
%14 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%15 = call i32 @fclose(i32* %11)
%16 = icmp eq i32 %14, 1
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
store i64 %19, i64* %1
br label %20
20: ; preds = %13, %17, %7
%21 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%22 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %31, label %24
24: ; preds = %20
%25 = call i32 @fscanf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%26 = call i32 @fclose(i32* %22)
%27 = icmp eq i32 %25, 1
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
br label %31
31: ; preds = %20, %28
%32 = phi i64 [ %30, %28 ], [ 512, %20 ]
store i64 %32, i64* %2
br label %33
33: ; preds = %31, %24
br label %34
34: ; preds = %33, %3
ret void
}