int read_fun(struct pngw_arg *p) {
  static int x = 0;
  static int y = 0;
  int k;
  if (x < 32 && y < 32) {
    k = 0;
  } else if (y < 32) {
    k = 1;
  } else if (x < 32) {
    k = 2;
  } else {
    k = 0;
  }
  x++;
  if (x == 640) {
    x = 0;
    y++;
  }
  return k;
}


x86 assembly (clang, -O0):
<read_fun>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
cmpl   $0x20,0x2f15(%rip)
jge    112e <read_fun+0x2e>
cmpl   $0x20,0x2f0c(%rip)
jge    112e <read_fun+0x2e>
movl   $0x0,-0xc(%rbp)
jmp    1171 <read_fun+0x71>
cmpl   $0x20,0x2ef3(%rip)
jge    1147 <read_fun+0x47>
movl   $0x1,-0xc(%rbp)
jmp    116c <read_fun+0x6c>
cmpl   $0x20,0x2ed6(%rip)
jge    1160 <read_fun+0x60>
movl   $0x2,-0xc(%rbp)
jmp    1167 <read_fun+0x67>
movl   $0x0,-0xc(%rbp)
jmp    116c <read_fun+0x6c>
jmp    1171 <read_fun+0x71>
mov    0x2ead(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ea4(%rip)
cmpl   $0x280,0x2e9a(%rip)
jne    11a9 <read_fun+0xa9>
movl   $0x0,0x2e8a(%rip)
mov    0x2e88(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e7f(%rip)
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_fun>:
mov    0x2f1e(%rip),%ecx
mov    0x2f1c(%rip),%edx
lea    0x1(%rcx),%eax
mov    %eax,0x2f0f(%rip)
cmp    $0x280,%eax
jne    112f <read_fun+0x2f>
movl   $0x0,0x2efe(%rip)
lea    0x1(%rdx),%eax
mov    %eax,0x2ef9(%rip)
xor    %esi,%esi
cmp    $0x20,%ecx
setl   %sil
add    %esi,%esi
xor    %eax,%eax
cmp    $0x20,%edx
mov    $0x1,%edx
cmovge %esi,%edx
cmovge %edx,%eax
cmp    $0x20,%ecx
cmovge %edx,%eax
ret

LLVM IR (-O0):
%struct.pngw_arg = type opaque
@read_fun.x = internal global i32 0
@read_fun.y = internal global i32 0
define i32 @read_fun(%struct.pngw_arg* %0) {
%2 = alloca %struct.pngw_arg*
%3 = alloca i32
store %struct.pngw_arg* %0, %struct.pngw_arg** %2
%4 = load i32, i32* @read_fun.x
%5 = icmp slt i32 %4, 32
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @read_fun.y
%8 = icmp slt i32 %7, 32
br i1 %8, label %9, label %10
9: ; preds = %6
store i32 0, i32* %3
br label %21
10: ; preds = %6, %1
%11 = load i32, i32* @read_fun.y
%12 = icmp slt i32 %11, 32
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 1, i32* %3
br label %20
14: ; preds = %10
%15 = load i32, i32* @read_fun.x
%16 = icmp slt i32 %15, 32
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 2, i32* %3
br label %19
18: ; preds = %14
store i32 0, i32* %3
br label %19
19: ; preds = %18, %17
br label %20
20: ; preds = %19, %13
br label %21
21: ; preds = %20, %9
%22 = load i32, i32* @read_fun.x
%23 = add nsw i32 %22, 1
store i32 %23, i32* @read_fun.x
%24 = load i32, i32* @read_fun.x
%25 = icmp eq i32 %24, 640
br i1 %25, label %26, label %29
26: ; preds = %21
store i32 0, i32* @read_fun.x
%27 = load i32, i32* @read_fun.y
%28 = add nsw i32 %27, 1
store i32 %28, i32* @read_fun.y
br label %29
29: ; preds = %26, %21
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.pngw_arg = type opaque
@read_fun.x = internal unnamed_addr global i32 0
@read_fun.y = internal unnamed_addr global i32 0
define i32 @read_fun(%struct.pngw_arg* nocapture readnone %0) {
%2 = load i32, i32* @read_fun.x
%3 = icmp slt i32 %2, 32
%4 = load i32, i32* @read_fun.y
%5 = icmp slt i32 %4, 32
%6 = add nsw i32 %2, 1
store i32 %6, i32* @read_fun.x
%7 = icmp eq i32 %6, 640
br i1 %7, label %8, label %10
8: ; preds = %1
store i32 0, i32* @read_fun.x
%9 = add nsw i32 %4, 1
store i32 %9, i32* @read_fun.y
br label %10
10: ; preds = %8, %1
%11 = select i1 %3, i1 %5, i1 false
%12 = select i1 %3, i32 2, i32 0
%13 = select i1 %5, i32 1, i32 %12
%14 = select i1 %11, i32 0, i32 %13
ret i32 %14
}